%%
%% This is file `pdfmanagement-testphase.ltx',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pdfmanagement-testphase.dtx  (with options: `header')
%% l3pdfdict.dtx  (with options: `package')
%% l3pdfmanagement.dtx  (with options: `package')
%% ltdocinit.dtx  (with options: `package')
%% l3pdfannot.dtx  (with options: `package')
%% l3pdfxform.dtx  (with options: `package')
%% l3pdfmeta.dtx  (with options: `package')
%% l3pdftools.dtx  (with options: `package')
%% l3pdffile.dtx  (with options: `package')
%% 
%% Copyright (C) 2019-2021 The LaTeX Project
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    https://www.latex-project.org/lppl.txt
%% 
%% This file is part of the "LaTeX PDF management testphase bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: pdfmanagement-testphase.dtx
\ProvidesExplFile{pdfmanagement-testphase.ltx}{2024-04-09}{0.96h}
  {PDF~management~code~(testphase)}
\bool_new:N\l__pdfmanagement_delayed_shipout_bool
\msg_new:nnn {pdfmanagement}{delayed-shipout}
  {
    The~engine~is~too~old!\\
    \tl_to_str:n{\pdf_bdc_shipout:ee}~can~not~be~used.
  }
\sys_if_engine_luatex:T
 {
   \int_compare:nNnT {\tex_luatexversion:D} > {116}
    {
      \bool_set_true:N\l__pdfmanagement_delayed_shipout_bool
    }
 }
\sys_if_engine_pdftex:T
 {
   \fp_compare:nNnT{\int_use:N\tex_pdftexversion:D.\tex_pdftexrevision:D}>{140.24}
    {
      \bool_set_true:N\l__pdfmanagement_delayed_shipout_bool
    }
 }
\sys_if_engine_ptex:T
 {
   \int_compare:nNnT{\tex_epTeXversion:D} > {230213}
    {
      \bool_set_true:N\l__pdfmanagement_delayed_shipout_bool
    }
 }
\sys_if_engine_uptex:T
 {
   \int_compare:nNnT{\tex_epTeXversion:D} > {230213}
    {
      \bool_set_true:N\l__pdfmanagement_delayed_shipout_bool
    }
 }
\sys_if_engine_xetex:T
 {
   \fp_compare:nNnT{\int_use:N\tex_XeTeXversion:D\tex_XeTeXrevision:D} > {0.999994}
    {
      \bool_set_true:N\l__pdfmanagement_delayed_shipout_bool
    }
 }
%% File: l3pdfdict.dtx
\cs_new:Npn \__pdfdict_get_type:n #1
  {
    \str_case_e:nn { \str_head:n{#1} }
     {
       {g}{global}
       {l}{local}
     }
  }
\msg_new:nnn  { pdfdict } { show-dict }
  { %#1: name of the dictionary
    %#2: expanded content
    %#3: type
    The~#3~dictionary~'#1'~
    \tl_if_empty:nTF {#2}
      { is~empty \\>~ . }
      { contains~the~pairs~(without~outer~braces): #2 . }
  }
\msg_new:nnn  { pdfdict } { unknown-dict }
  {
    The~dictionary~'#1'~is~unknown.
  }
\msg_new:nnn  { pdfdict } { dict-already-defined  }
  {
    The~#2~dictionary~'#1'~is~already~defined.
  }
\msg_new:nnn  { pdfdict } { empty-value }
              { The~value~#1~for~#2~is~blank~and~will~be~ignored }

\msg_new:nnn  { pdfdict } { invalid-name }
              { Name~'#1'~is~not~valid\\
                Names~of~dictionaries~should~start~with~'g_'~or~'l_' }


\seq_new:N \g__pdfdict_lnames_seq
\seq_new:N \g__pdfdict_gnames_seq
\cs_new:Npn \__pdfdict_name:n #1  % #1 dictionary name
  {
    \str_head:n{#1}__pdfdict_/#1_prop
  }
\cs_set_eq:NN \__kernel_pdfdict_name:n \__pdfdict_name:n

\cs_new_protected:Npn \__pdfdict_new:n #1
  {
    \__pdfdict_if_exist:nTF { #1 }
      {
        \msg_error:nnee
          { pdfdict }
          { dict-already-defined }
          { \tl_to_str:n {#1} }
          { \__pdfdict_get_type:n{#1} }
       }
       {
         \str_case_e:nnF { \str_head:n{#1} }
           {
             {g}
             {
                 \prop_new:c  { \__pdfdict_name:n { #1 } }
                 \seq_gput_right:cn {g__pdfdict_gnames_seq} { #1 }
             }
             {l}
             {
                 \prop_new:c  { \__pdfdict_name:n { #1 } }
                 \seq_gput_right:cn {g__pdfdict_lnames_seq} { #1 }
             }
           }
           {
             \msg_error:nne{pdfdict}{invalid-name}{\tl_to_str:n{#1}}
           }
       }
  }

\cs_set_eq:NN \pdfdict_new:n \__pdfdict_new:n
\cs_new_protected:Npn \__pdfdict_set_eq:nn #1 #2
  {
    \__pdfdict_if_exist:nTF  { #2 }
      {
        \__pdfdict_if_exist:nF { #1 }
          {
            \__pdfdict_new:n { #1 }
          }
        \prop_set_eq:cc { \__pdfdict_name:n {#1} }{ \__pdfdict_name:n {#2} }
      }
      {
         \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
      }
  }

\cs_set_eq:NN \pdfdict_set_eq:nn \__pdfdict_set_eq:nn

\cs_new_protected:Npn \__pdfdict_gset_eq:nn #1 #2
  {
    \__pdfdict_if_exist:nTF { #2 }
      {
        \__pdfdict_if_exist:nF { #1 }
          {
            \__pdfdict_new:n { #1 }
          }
        \prop_gset_eq:cc { \__pdfdict_name:n {#1} }{ \__pdfdict_name:n {#2} }
      }
      {
         \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
      }
  }

\cs_set_eq:NN \pdfdict_gset_eq:nn \__pdfdict_gset_eq:nn
\prg_new_conditional:Npnn \__pdfdict_if_exist:n #1 { p , T , F , TF }
  {
    \prop_if_exist:cTF
      { \__pdfdict_name:n { #1 }  }
      { \prg_return_true:  }
      { \prg_return_false: }
  }
\prg_set_eq_conditional:NNn
  \pdfdict_if_exist:n \__pdfdict_if_exist:n { p , T , F , TF }
\prg_new_conditional:Npnn \__pdfdict_if_empty:n #1 { p , T , F , TF }
  {
    \prop_if_empty:cTF
      { \__pdfdict_name:n { #1 } }
      { \prg_return_true:  }
      { \prg_return_false: }
  }

\prg_set_eq_conditional:NNn
  \pdfdict_if_empty:n \__pdfdict_if_empty:n { p , T , F , TF }
\cs_new_protected:Npn \__pdfdict_put:nnn #1 #2 #3  %#1 (local) dict, #2 name, #3 value
  {
    \tl_if_blank:nTF { #3 }
      {
        \msg_warning:nnnn { pdfdict }{ empty-value }{ #2 } { #1 }
      }
      {
        \__pdfdict_if_exist:nTF  { #1 }
          {
            \exp_args:Nne \prop_put:cnn
              { \__pdfdict_name:n { #1 } }{ \str_convert_pdfname:n { #2 } } { #3 }
          }
          {
            \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
          }
      }
  }

\cs_set_eq:NN \pdfdict_put:nnn \__pdfdict_put:nnn
\cs_generate_variant:Nn \pdfdict_put:nnn {nne,nno,nee,nnx}

\cs_new_protected:Npn \__pdfdict_gput:nnn #1 #2 #3  %#1 global dict, #2 name, #3 value
  {
    \tl_if_empty:nTF { #3 }
      {
        \msg_warning:nnnn { pdfdict }{ empty-value }{ #2 } { #1 }
      }
      {
        \__pdfdict_if_exist:nTF { #1 }
          {
            \exp_args:Nne \prop_gput:cnn
              { \__pdfdict_name:n { #1 } }{ \str_convert_pdfname:n { #2 } } { #3 }
          }
          {
            \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
          }
      }
  }

\cs_set_eq:NN \pdfdict_gput:nnn \__pdfdict_gput:nnn
\cs_generate_variant:Nn \pdfdict_gput:nnn {nne,nno,nee,nnx}
\cs_new_protected:Npn \__pdfdict_get:nnN  #1 #2 #3 %dict,key,macro
  {
    \__pdfdict_if_exist:nTF { #1 }
      {
        \exp_args:Nne \prop_get:cnN
          { \__pdfdict_name:n { #1 } }
          { \str_convert_pdfname:n { #2 } } #3
      }
      {
        \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
      }
  }

\cs_set_eq:NN \pdfdict_get:nnN \__pdfdict_get:nnN
\cs_new_protected:Npn \__pdfdict_remove:nn #1 #2 %dict,name
  {
    \__pdfdict_if_exist:nTF { #1 }
      {
        \exp_args:Nne \prop_remove:cn
          { \__pdfdict_name:n  { #1 } }{ \str_convert_pdfname:n { #2 } }
      }
      {
        \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
      }
  }
\cs_set_eq:NN \pdfdict_remove:nn \__pdfdict_remove:nn

\cs_new_protected:Npn \__pdfdict_gremove:nn #1 #2 %dict,name
  {
    \__pdfdict_if_exist:nTF  { #1 }
       {
         \exp_args:Nne \prop_gremove:cn
           { \__pdfdict_name:n  { #1 } }{ \str_convert_pdfname:n { #2 } }
       }
       {
         \msg_error:nnn { pdfdict } { unknown-dict } { #1 }
       }
  }

\cs_set_eq:NN \pdfdict_gremove:nn \__pdfdict_gremove:nn
\cs_new_protected:Npn \__pdfdict_show:Nn #1#2 %#1 message command, #2 dict
  {
    \prop_if_exist:cTF { \__pdfdict_name:n { #2 } }
       {
         #1
            { pdfdict }
            { show-dict }
            { \tl_to_str:n {#2}  }
            { \prop_map_function:cN {\__pdfdict_name:n { #2 }} \msg_show_item:nn }
            { \__pdfdict_get_type:n{#2} }
            { }
       }
       {
         #1 { pdfdict } { unknown-dict } { #2 } {}{}{}
       }
  }
\cs_new_protected:Npn \pdfdict_show:n #1
  {
    \__pdfdict_show:Nn \msg_show:nneeee {#1}
  }
\cs_new:Npn \__pdfdict_item:nn #1 #2 %#1 name, #2 value
  {
    \tl_if_blank:nF {#2} { /#1~#2~ }
  }
\cs_generate_variant:Nn \__pdfdict_item:nn {ne}
\cs_set_eq:NN \pdfdict_item:nn \__pdfdict_item:nn
\cs_generate_variant:Nn \pdfdict_item:nn {ne}
\cs_new:Npn \__pdfdict_use:n #1  %#1 dict
  {
    \prop_map_function:cN { \__pdfdict_name:n { #1 } } \__pdfdict_item:ne
  }

\cs_set_eq:NN \pdfdict_use:n \__pdfdict_use:n
%% File: l3pdfmanagement.dtx


\msg_new:nnn  { pdfmanagement } { unknown-dict }
              { The~PDF~management~resource~'#1'~is~unknown. }

\msg_new:nnn  { pdfmanagement } { empty-value }
              { The~value~for~#1~is~empty~and~will~be~ignored }

\msg_new:nnn  { pdfmanagement } { no-removal }
              { It~is~not~possible~to~remove~values~from~'#1'.}

\msg_new:nnn  { pdfmanagement } { no-show }
              { It~is~not~possible~to~show~the~content~of~'#1'.}

\msg_new:nnn  { pdfmanagement } { name-exist }
              { The~name~'#1'~has~already~been~used~for~name~tree~'#2'.}

\msg_new:nnn  { pdfmanagement } { show-dict }
  {
    The~PDF~resource~'#1'~
    \tl_if_empty:nTF {#2}
      { is~empty \\>~ . }
      { contains~the~pairs~(without~outer~braces): #2 . }
  }
\msg_new:nnn  { pdfmanagement } { dict-already-defined  }
  {
    The~path~'#1'~is~already~defined.
  }
\msg_new:nnn  { pdfmanagement } { inactive  }
  {
    The~PDF~resources~management~is~not~active\\
    command~'#1'~ignored.
  }
\tl_new:N \l__pdfmanagement_tmpa_tl
\tl_new:N \l__pdfmanagement_tmpb_tl
\seq_new:N \l__pdfmanagement_tmpa_seq

\bool_new:N \g__pdfmanagement_active_bool
\prg_new_conditional:Npnn \__pdfmanagement_if_active:  { p , T , F , TF }
  {
    \bool_if:NTF \g__pdfmanagement_active_bool
      { \prg_return_true:  }
      { \prg_return_false: }
  }
\prg_set_eq_conditional:NNn
  \pdfmanagement_if_active: \__pdfmanagement_if_active: { p , T , F , TF }

\cs_set_eq:NN \IfPDFManagementActiveTF\pdfmanagement_if_active:TF
\hook_new:n {pdfmanagement/add}
\cs_new_protected:Npn \pdfmanagement_add:nnn #1 #2 #3
  {
    \__pdfmanagement_if_active:TF
      {
        \pdfdict_if_exist:nTF { g__pdf_Core/#1 }
          {
            \hook_gput_code:nnn
              {pdfmanagement/add}
              {pdfmanagement}
              {
                \__pdfmanagement_handler_gput:nnn { #1 }{ #2 }{ #3 }
              }
          }
          {
            \msg_error:nnn{pdfmanagement}{unknown-dict}{#1}
          }
      }
      {
        \msg_warning:nne {pdfmanagement}{inactive}
          {\tl_to_str:n {\pdfmanagement_add:nnn}}
      }
  }

\cs_generate_variant:Nn \pdfmanagement_add:nnn {nne,nee,eee,nnx,nxx,xxx}
\cs_set_eq:NN \PDFManagementAdd \pdfmanagement_add:eee
\tl_new:N \g__kernel_pdfmanagement_thispage_shipout_code_tl
\tl_new:N \g__kernel_pdfmanagement_lastpage_shipout_code_tl
\tl_new:N \g__kernel_pdfmanagement_end_run_code_tl
\tl_gset:Nn \g__kernel_pdfmanagement_thispage_shipout_code_tl
  {
     \bool_if:NT \g__pdfmanagement_active_bool
       {
         \exp_args:NV \__pdf_backend_ThisPage_gpush:n      { \g_shipout_readonly_int }
         \exp_args:NV \__pdf_backend_PageResources_gpush:n { \g_shipout_readonly_int }
       }
  }

\tl_gset:Nn \g__kernel_pdfmanagement_end_run_code_tl
  {
    \bool_if:NT \g__pdfmanagement_active_bool
       {
         \__pdf_backend_PageResources_obj_gpush:          %ExtGState etc
         \__pdfmanagement_Pages_gpush:            %pagesattr
         \__pdfmanagement_Info_gpush:             %pdfinfo
         \__pdfmanagement_Catalog_gpush:
       }
  }



\cs_new_protected:Npn \__pdfmanagement_handler_gput:nnn #1 #2 #3  %#1 dict, #2 name, #3 value
  {
    \tl_if_empty:nTF { #3 }
      {
        \msg_none:nnn { pdfmanagement }{ empty-value }{ /#1/#2 }
      }
      {
        \pdfdict_if_exist:nTF { g__pdf_Core/#1 }
          {
            \cs_if_exist:cTF
              { __pdfmanagement_handler/#1/?_gput:nn } %general, name independant handler
              { \use:c {__pdfmanagement_handler/#1/?_gput:nn} {#2} {#3} }
              {
                \cs_if_exist:cTF
                  { __pdfmanagement_handler/#1/#2_gput:n }
                  { \use:c {__pdfmanagement_handler/#1/#2_gput:n} {#3} } %special handler
                  {
                    \exp_args:Nne
                    \prop_gput:cnn
                      { \__kernel_pdfdict_name:n { g__pdf_Core/#1 } }
                      { \str_convert_pdfname:n { #2 } }
                      { #3 }
                  }
              }
          }
          {
            \msg_error:nnn { pdfmanagement } { unknown-dict } { #1 }
          }
      }
  }

\cs_generate_variant:Nn \__pdfmanagement_handler_gput:nnn {nee}

\cs_new_protected:Npn \__pdfmanagement_get:nnN  #1 #2 #3 %path,key,macro
  {
    \exp_args:Nne
    \prop_get:cnN
      { \__kernel_pdfdict_name:n { g__pdf_Core/#1 } }
      { \str_convert_pdfname:n {#2} } #3
  }

\cs_new_protected:Npn \__pdfmanagement_handler_gremove:nn #1 #2 %path,key
  {
    \pdfdict_if_exist:nTF { g__pdf_Core/#1 }
          {
            \cs_if_exist:cTF
              { __pdfmanagement_handler/#1/?_gremove:n } %general, name independant handler
              { \use:c {__pdfmanagement_handler/#1/?_gremove:n} {#2} }
              {
                \cs_if_exist:cTF
                  { __pdfmanagement_handler/#1/#2_gremove: }
                  { \use:c {__pdfmanagement_handler/#1/#2_gremove:} } %special handler
                  {
                    \exp_args:Nne
                    \prop_gremove:cn
                      { \__kernel_pdfdict_name:n { g__pdf_Core/#1 } }
                      { \str_convert_pdfname:n {#2} }
                  }
              }
          }
          {
            \msg_error:nnn { pdfmanagement } { unknown-dict } { #1 }
          }
  }

\cs_new_protected:Npn \__pdfmanagement_gremove:nn #1 #2 %path,key
  {
    \pdfdict_if_exist:nTF { g__pdf_Core/#1 }
          {
            \exp_args:Nne
            \prop_gremove:cn
              { \__kernel_pdfdict_name:n { g__pdf_Core/#1 } }
              { \str_convert_pdfname:n{#2} }
          }
          {
            \msg_error:nnn { pdfmanagement } { unknown-dict } { #1 }
          }
  }

\cs_new_protected:Npn \__pdfmanagement_show:Nn #1#2
  {
    \cs_if_exist:cTF
      { __pdfmanagement_handler/#2/?_show: } %general, name independant handler
      { \use:c {__pdfmanagement_handler/#2/?_show:} }
      {
        \prop_if_exist:cTF { \__kernel_pdfdict_name:n { g__pdf_Core/#2 } }
          {
             #1
               { pdfmanagement } { show-dict }
               { \tl_to_str:n {#2} }
               {
                 \prop_map_function:cN
                  {\__kernel_pdfdict_name:n { g__pdf_Core/#2 }}
                  \msg_show_item:nn
               }
               { } { }
          }
          {
            #1 { pdfmanagement } { unknown-dict } {#2}{}{}{}
          }
       }
  }

\cs_new_protected:Npn \__pdfmanagement_show:n #1  %path
  {
    \prop_show:c { \__kernel_pdfdict_name:n { g__pdf_Core/#1 } }
  }
\cs_new_protected:Npn \pdfmanagement_show:n #1
  {
    \__pdfmanagement_show:Nn \msg_show:nneeee {#1}
  }
\cs_new_protected:Npn \pdfmanagement_remove:nn #1 #2
  {
    \pdfdict_if_exist:nTF { g__pdf_Core/#1 }
      {
        \__pdfmanagement_handler_gremove:nn { #1 }{ #2 }
      }
      {
        \msg_error:nnn{pdfmanagement}{unknown-dict}{#1}
      }
  }
\cs_new_protected:Npn \pdfmanagement_get:nnN #1 #2 #3
  {
    \pdfdict_if_exist:nTF { g__pdf_Core/#1 }
      {
        \__pdfmanagement_get:nnN { #1 }{ #2 } #3
      }
      {
        \msg_error:nnn{pdfmanagement}{unknown-dict}{#1}
      }
  }
\pdfdict_new:n { g__pdf_Core/Info}
\cs_new_protected:Npn \__pdfmanagement_Info_gpush:
  {
    \prop_map_function:cN
      { \__kernel_pdfdict_name:n { g__pdf_Core/Info} }
      \__pdf_backend_info_gput:nn
    \prop_gclear:c { \__kernel_pdfdict_name:n { g__pdf_Core/Info} }
  }
\pdfdict_new:n { g__pdf_Core/Pages}
\cs_new_protected:Npn \__pdfmanagement_Pages_gpush:
  {
    \pdfdict_if_empty:nF { g__pdf_Core/Pages}
      {
        \exp_args:Ne \__pdf_backend_Pages_primitive:n
          {
            \pdfdict_use:n { g__pdf_Core/Pages}
          }
      }
  }

\pdfdict_new:n { g__pdf_Core/Page }
\pdfdict_new:n { g__pdf_Core/ThisPage }

\cs_new_protected:cpn { __pdfmanagement_handler/Page/?_gput:nn } #1 #2
  {
    \__pdf_backend_Page_gput:nn { #1 }{ #2 }
  }
\cs_new_protected:cpn { __pdfmanagement_handler/Page/?_gremove:n } #1
  {
    \__pdf_backend_Page_gremove:n { #1 }
  }

\cs_new_protected:cpn { __pdfmanagement_handler/ThisPage/?_gput:nn } #1 #2
  {
    \prop_gput:cnn  { \__kernel_pdfdict_name:n { g__pdf_Core/ThisPage } }{ #1 } { #2 }
    \bool_if:NT \g__pdfmanagement_active_bool
      {
        \__pdf_backend_ThisPage_gput:nn { #1 }{ #2 }
      }
  }

\cs_new_protected:cpn { __pdfmanagement_handler/ThisPage/?_gremove:n } #1
  {
    \msg_warning:nnn { pdfmanagement } { no-removal }{ThisPage}
  }

\cs_new_protected:cpn { __pdfmanagement_handler/ThisPage/?_show: }
  {
    \msg_warning:nnn { pdfmanagement } { no-show }{ThisPage}
  }

\clist_const:Nn \c__pdfmanagement_PageResources_clist
  {
    ExtGState,
    ColorSpace,
    Pattern,
    Shading,
  }

\clist_map_inline:Nn \c__pdfmanagement_PageResources_clist
  {
    \pdfdict_new:n { g__pdf_Core/Page/Resources/#1}
  }
\cs_new_protected:cpn { __pdfmanagement_handler/Page/Resources/ExtGState/?_gput:nn } #1 #2
  {
    \__pdf_backend_PageResources_gput:nnn {ExtGState} { #1 }{ #2 }
  }

\cs_new_protected:cpn { __pdfmanagement_handler/Page/Resources/ColorSpace/?_gput:nn } #1 #2
  {
    \__pdf_backend_PageResources_gput:nnn {ColorSpace} { #1 }{ #2 }
  }

\cs_new_protected:cpn { __pdfmanagement_handler/Page/Resources/Shading/?_gput:nn } #1 #2
  {
    \__pdf_backend_PageResources_gput:nnn {Shading} { #1 }{ #2 }
  }

\cs_new_protected:cpn { __pdfmanagement_handler/Page/Resources/Pattern/?_gput:nn } #1 #2
  {
    \__pdf_backend_PageResources_gput:nnn {Pattern} { #1 }{ #2 }
  }
\pdfdict_new:n { g__pdf_Core/Catalog}

\clist_const:Nn \c__pdfmanagement_Catalog_toplevel_clist
  {
    Collection,
    DPartRoot,
    Lang,
    Legal,
    Metadata,
    NeedsRendering,
    OCProperties/D,
    OpenAction,
    PageLabels,
    PageLayout,
    PageMode,
    Perms,
    PieceInfo,
    SpiderInfo,
    StructTreeRoot,
    Threads,
    URI,
    Version
  }

\clist_const:Nn \c__pdfmanagement_Catalog_sub_clist
  {
    AA,
    AcroForm,
    AcroForm/DR,
    AcroForm/DR/Font,
    MarkInfo,
    ViewerPreferences,
    OCProperties
  }

\clist_map_inline:Nn \c__pdfmanagement_Catalog_sub_clist
  {
    \pdfdict_new:n { g__pdf_Core/Catalog/#1}
  }

\clist_const:Nn \c__pdfmanagement_Catalog_seq_clist
  {
    AF,
    OCProperties/OCGs,
    OCProperties/Configs,
    OutputIntents,
    Requirements,
    AcroForm/Fields,
    AcroForm/CO
  }

\clist_const:Nn \c__pdfmanagement_Catalog_nametree_clist
  {
    AP,
    JavaScript,
  }
\clist_map_inline:Nn \c__pdfmanagement_Catalog_seq_clist
 {
   \seq_new:c { g__pdfmanagement_/Catalog/#1_seq } % new name later
   \cs_new_protected:cpn { __pdfmanagement_handler/Catalog/#1_gput:n } ##1
     {
       \seq_gput_right:cn { g__pdfmanagement_/Catalog/#1_seq } {  ##1  }
     }
 }

\cs_new_protected:cpn { __pdfmanagement_handler/Catalog/OCProperties/D_gput:n } #1
  {
    \seq_gput_left:cn
      { g__pdfmanagement_/Catalog/OCProperties/Configs_seq }
      {  #1  }
  }
\cs_new_protected:Npn \__pdfmanagement_nametree_add_aux:nnn #1 #2 #3
  %#1 name tree, #2 sanitized name #3 value
  {
     \prop_get:coNTF
       { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/#1 }}
       { #2 }
       \l__pdfmanagement_tmpb_tl
       {
         \msg_error:nnnn{pdfmanagement}{name-exist}{#2}{#1}
       }
       {
         \prop_gput:con
           { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/#1 }}
           { #2 }
           { #3 }
       }
  }
\clist_map_inline:Nn \c__pdfmanagement_Catalog_nametree_clist
 {
   \pdfdict_new:n { g__pdf_Core/Catalog/Names/#1}
   \cs_new_protected:cpn { __pdfmanagement_handler/Catalog/Names/#1/?_gput:nn } ##1 ##2
     {
       \pdf_string_from_unicode:nnN {utf8/string}{##1}\l__pdfmanagement_tmpa_tl
       \exp_args:Nno
         \__pdfmanagement_nametree_add_aux:nnn {#1}{\l__pdfmanagement_tmpa_tl}{##2}
     }
 }
\pdfdict_new:n { g__pdf_Core/Catalog/Names/EmbeddedFiles}
\cs_new_protected:cpn { __pdfmanagement_handler/Catalog/Names/EmbeddedFiles/?_gput:nn } #1 #2
  {
    \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdfmanagement_tmpa_tl
    \exp_args:Nno
    \__pdfmanagement_nametree_add_aux:nnn
      {EmbeddedFiles}{\l__pdfmanagement_tmpa_tl}{#2}
    \exp_args:No
    \__pdf_backend_NamesEmbeddedFiles_add:nn {\l__pdfmanagement_tmpa_tl}{#2}
  }
\cs_new_protected:Npn \__pdfmanagement_Catalog_gpush:
  {
    \use:c { __pdfmanagement_/Catalog/AA_gpush: }
    \use:c { __pdfmanagement_/Catalog/AcroForm_gpush: }
    \use:c { __pdfmanagement_/Catalog/AF_gpush: }
    \use:c { __pdfmanagement_/Catalog/MarkInfo_gpush: }
    \pdfmeta_standard_verify:nT {Catalog_no_OCProperties}
      {
        \use:c { __pdfmanagement_/Catalog/OCProperties_gpush: }
      }
    \use:c { __pdfmanagement_/Catalog/OutputIntents_gpush: }
    \use:c { __pdfmanagement_/Catalog/Requirements_gpush: }
    \use:c { __pdfmanagement_/Catalog/ViewerPreferences_gpush: }
    % output the single values:
    \prop_map_function:cN
      { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog} }
      \__pdf_backend_catalog_gput:nn
    % output names tree:
    \use:c{ __pdfmanagement_/Catalog/Names_gpush:n } {EmbeddedFiles}
    \clist_map_inline:Nn \c__pdfmanagement_Catalog_nametree_clist
     {
      \use:c{ __pdfmanagement_/Catalog/Names_gpush:n } {##1}
     }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/AA_gpush: }
  {
    \prop_if_empty:cF
     { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AA } }
     {
       \pdf_object_new:n  { __pdfmanagement/Catalog/AA }
       \pdf_object_write:nne
            { __pdfmanagement/Catalog/AA }{ dict }
            { \pdfdict_use:n { g__pdf_Core/Catalog/AA } }
       \exp_args:Nne
         \__pdf_backend_catalog_gput:nn
           {AA}
           {
             \pdf_object_ref:n { __pdfmanagement/Catalog/AA }
           }
     }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/AcroForm_gpush: }
  {
    \seq_if_empty:cF { g__pdfmanagement_/Catalog/AcroForm/Fields_seq }
      {
        \pdf_object_new:n  { __pdfmanagement/Catalog/AcroForm/Fields }
        \pdf_object_write:nne
            { __pdfmanagement/Catalog/AcroForm/Fields } { array }
            { \seq_use:cn { g__pdfmanagement_/Catalog/AcroForm/Fields_seq } {~} }
        \exp_args:Nnne
          \prop_gput:cnn %we have to use \prop here to avoid the handler ...
            { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm } }
            { Fields }
            { \pdf_object_ref:n { __pdfmanagement/Catalog/AcroForm/Fields } }
      }
    \seq_if_empty:cF { g__pdfmanagement_/Catalog/AcroForm/CO_seq }
      {
        \pdf_object_new:n  { __pdfmanagement/Catalog/AcroForm/CO }
        \pdf_object_write:nne
            { __pdfmanagement/Catalog/AcroForm/CO } { array }
            { \seq_use:cn { g__pdfmanagement_/Catalog/AcroForm/CO_seq } {~} }
        \exp_args:Nnne
          \prop_gput:cnn %we have to use \prop here to avoid the handler ...
            { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm } }
            { CO }
            { \pdf_object_ref:n { __pdfmanagement/Catalog/AcroForm/CO } }
      }
     \prop_if_empty:cF { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm/DR/Font}}
       {
         \pdf_object_new:n { __pdfmanagement/Catalog/AcroForm/DR/Font }
         \pdf_object_write:nne
             { __pdfmanagement/Catalog/AcroForm/DR/Font } { dict }
             { \pdfdict_use:n { g__pdf_Core/Catalog/AcroForm/DR/Font } }
         \exp_args:Nnne
           \prop_gput:cnn %we have to use \prop here to avoid the handler ...
             { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm/DR } }
             { Font }
             { \pdf_object_ref:n { __pdfmanagement/Catalog/AcroForm/DR/Font } }
       }
     \prop_if_empty:cF { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm/DR}}
       {
         \pdf_object_new:n { __pdfmanagement/Catalog/AcroForm/DR }
         \pdf_object_write:nne
             { __pdfmanagement/Catalog/AcroForm/DR } { dict }
             { \pdfdict_use:n { g__pdf_Core/Catalog/AcroForm/DR } }
         \exp_args:Nnne
           \prop_gput:cnn %we have to use \prop here to avoid the handler ...
             { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm } }
             { DR }
             { \pdf_object_ref:n { __pdfmanagement/Catalog/AcroForm/DR } }
       }
     \prop_if_empty:cF { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/AcroForm} }
       {
         \pdf_object_new:n { __pdfmanagement/Catalog/AcroForm }
         \pdf_object_write:nne
             { __pdfmanagement/Catalog/AcroForm } { dict }
             { \pdfdict_use:n { g__pdf_Core/Catalog/AcroForm } }
         \exp_args:Nnne
           \__pdfmanagement_handler_gput:nnn
             { Catalog }
             { AcroForm }
             { \pdf_object_ref:n { __pdfmanagement/Catalog/AcroForm } }
       }
  }

\cs_new_protected:cpn { __pdfmanagement_/Catalog/AF_gpush: }
  {
    \seq_if_empty:cF
     { g__pdfmanagement_/Catalog/AF_seq }
     {
       \pdf_object_new:n  { __pdfmanagement/Catalog/AF }
       \pdf_object_write:nne
            { __pdfmanagement/Catalog/AF } { array }
            { \seq_use:cn { g__pdfmanagement_/Catalog/AF_seq } {~} }
       \exp_args:Nne
         \__pdf_backend_catalog_gput:nn
           {AF}
           {
             \pdf_object_ref:n {__pdfmanagement/Catalog/AF}
           }
     }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/MarkInfo_gpush: }
  {
    \prop_if_empty:cF
     { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/MarkInfo } }
     {
       \pdf_object_new:n  { __pdfmanagement/Catalog/MarkInfo }
       \pdf_object_write:nne
          { __pdfmanagement/Catalog/MarkInfo } { dict }
          { \pdfdict_use:n { g__pdf_Core/Catalog/MarkInfo } }
       \exp_args:Nne
         \__pdf_backend_catalog_gput:nn
           {MarkInfo}
           {
             \pdf_object_ref:n {__pdfmanagement/Catalog/MarkInfo}
           }
     }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/OCProperties_gpush: }
  {
   \int_compare:nNnT
      {
        ( \seq_count:c { g__pdfmanagement_/Catalog/OCProperties/OCGs_seq }  )*
        ( \seq_count:c { g__pdfmanagement_/Catalog/OCProperties/Configs_seq } )
      }
      >
      { 0 }
      {
        \pdf_object_new:n  { __pdfmanagement/Catalog/OCProperties }
        \seq_gpop_left:cN { g__pdfmanagement_/Catalog/OCProperties/Configs_seq} \l__pdfmanagement_tmpa_tl
        \pdf_object_write:nne {__pdfmanagement/Catalog/OCProperties} {dict}
           {
              /OCGs~[ \seq_use:cn { g__pdfmanagement_/Catalog/OCProperties/OCGs_seq } {~} ]
              /D~\l__pdfmanagement_tmpa_tl~
              \seq_if_empty:cF { g__pdfmanagement_/Catalog/OCProperties/Configs_seq }
                {
                  /Configs~
                  [ \seq_use:cn { g__pdfmanagement_/Catalog/OCProperties/Configs_seq} {~} ]
                }
           }
        \exp_args:Nne
          \__pdf_backend_catalog_gput:nn
            { OCProperties }
            { \pdf_object_ref:n {__pdfmanagement/Catalog/OCProperties} }
      }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/OutputIntents_gpush: }
  {
    \seq_if_empty:cF
     { g__pdfmanagement_/Catalog/OutputIntents_seq }
     {
       \pdf_object_new:n  { __pdfmanagement/Catalog/OutputIntents }
       \pdf_object_write:nne
            { __pdfmanagement/Catalog/OutputIntents } { array }
            { \seq_use:cn { g__pdfmanagement_/Catalog/OutputIntents_seq } {~} }
       \exp_args:Nne
         \__pdf_backend_catalog_gput:nn
           {OutputIntents}
           {
             \pdf_object_ref:n {__pdfmanagement/Catalog/OutputIntents}
           }
     }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/Requirements_gpush: }
  {
    \seq_if_empty:cF
     { g__pdfmanagement_/Catalog/Requirements_seq }
     {
       \pdf_object_new:n  { __pdfmanagement/Catalog/Requirements }
       \pdf_object_write:nne
            { __pdfmanagement/Catalog/Requirements } { array }
            { \seq_use:cn { g__pdfmanagement_/Catalog/Requirements_seq } {~} }
       \exp_args:Nne
         \__pdf_backend_catalog_gput:nn
           {Requirements}
           {
             \pdf_object_ref:n { __pdfmanagement/Catalog/Requirements }
           }
     }
  }
\cs_new_protected:cpn { __pdfmanagement_/Catalog/ViewerPreferences_gpush: }
  {
    \prop_if_empty:cF
     { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/ViewerPreferences } }
     {
       \pdf_object_new:n  { __pdfmanagement/Catalog/ViewerPreferences }
       \pdf_object_write:nne
            { __pdfmanagement/Catalog/ViewerPreferences } { dict }
            { \pdfdict_use:n { g__pdf_Core/Catalog/ViewerPreferences } }
       \exp_args:Nne
         \__pdf_backend_catalog_gput:nn
           {ViewerPreferences}
           {
             \pdf_object_ref:n {__pdfmanagement/Catalog/ViewerPreferences}
           }
     }
  }
\int_new:N \g__pdfmanagement_EmbeddedFiles_int
\cs_new:Npn \__pdfmanagement_EmbeddedFiles_name:
 {
   (
    l3ef
    \int_compare:nNnT {\g__pdfmanagement_EmbeddedFiles_int} < {10}
     {0}
    \int_compare:nNnT {\g__pdfmanagement_EmbeddedFiles_int} < {100}
     {0}
    \int_compare:nNnT {\g__pdfmanagement_EmbeddedFiles_int} < {1000}
     {0}
    \int_use:N \g__pdfmanagement_EmbeddedFiles_int
   )
 }
\pdfdict_new:n { g__pdf_Core/Catalog/Names }

\cs_new_protected:cpn { __pdfmanagement_handler/Catalog/Names/EmbeddedFiles_gput:n } #1
  {
    \int_gincr:N \g__pdfmanagement_EmbeddedFiles_int
    \exp_args:Nne
    \prop_gput:cnn
      { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/EmbeddedFiles }}
      { \__pdfmanagement_EmbeddedFiles_name: }
      { #1 }
     \exp_args:Ne
     \__pdf_backend_NamesEmbeddedFiles_add:nn {\__pdfmanagement_EmbeddedFiles_name:} { #1 }
  }
\cs_new_protected:cpn  { __pdfmanagement_/Catalog/Names_gpush:n } #1 %#1 name of name tree
 {
   \pdfdict_if_empty:nF { g__pdf_Core/Catalog/Names/#1 }
     {
       \seq_clear:N \l__pdfmanagement_tmpa_seq
       \prop_map_inline:cn
         {\__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/#1 }}
         { \seq_put_right:Nn \l__pdfmanagement_tmpa_seq {##1~##2}}
       \seq_sort:Nn  \l__pdfmanagement_tmpa_seq
         {
           \str_compare:nNnTF {##1} > {##2}
             { \sort_return_swapped: }
             { \sort_return_same: }
         }
       \exp_args:Nne \__pdf_backend_Names_gpush:nn
         {#1}
         {
           \seq_use:Nn \l__pdfmanagement_tmpa_seq {~}
         }
     }
 }
\cs_new_protected:cpn {__pdfmanagement_handler/Catalog/?_show:}
  {
    \iow_term:e
      {
        \iow_newline:
        The~Catalog~contains~in~the~top~level~the~single~value~entries
        \prop_map_function:cN
          {\__kernel_pdfdict_name:n { g__pdf_Core/Catalog }}
          \msg_show_item:nn
      }
    \clist_map_inline:Nn \c__pdfmanagement_Catalog_seq_clist
     {
       \seq_if_empty:cF {  g__pdfmanagement_/Catalog/##1_seq }
         {
           \iow_term:e
             {
               The~'##1'~array~contains~the~entries
               \seq_map_function:cN { g__pdfmanagement_/Catalog/##1_seq } \msg_show_item:n
             }
         }
      }
    \clist_map_inline:Nn \c__pdfmanagement_Catalog_sub_clist
      {
        \prop_if_empty:cF { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/##1 } }
          {
            \iow_term:e
              {
                The~Catalog~subdirectory~'##1'~contains~the~single~value~entries
                \prop_map_function:cN
                  {\__kernel_pdfdict_name:n { g__pdf_Core/Catalog/##1 }}
                  \msg_show_item:nn
              }
          }
      }
    \tl_show:e {\tl_to_str:n{\pdfmanagement_show:n{Catalog}}}
  }
\pdfdict_new:n { g__pdf_Core/Xform/Resources/Properties}
%% File: ltdocinit.dtx
\clist_if_exist:NF \g__pdfmanagement_firstaidoff_clist
  { \clist_new:N \g__pdfmanagement_firstaidoff_clist }
\tl_if_exist:NF \g__pdfmanagement_testphase_tl
 { \tl_new:N \g__pdfmanagement_testphase_tl }
\NewCommandCopy\DeclareDocumentMetadata\DocumentMetadata
\prop_new:N \g__pdfmanagement_documentproperties_prop %
\NewDocumentCommand\AddToDocumentProperties{O{\@currname}mm}
  {
    \exp_args:NNe
      \prop_gput:Nnn \g__pdfmanagement_documentproperties_prop
        {
          \tl_if_blank:eTF {#1}{top-level/}{#1/} #2
        }
        { #3}
  }
\NewExpandableDocumentCommand\GetDocumentProperties{m}
  {
    \prop_item:Nn \g__pdfmanagement_documentproperties_prop {#1}
  }
\cs_new:Npn\pdfmanagement_get_documentproperties:n #1
  {
    \prop_item:Nn \g__pdfmanagement_documentproperties_prop {#1}
  }
\prg_new_protected_conditional:Npnn
  \pdfmanagement_get_documentproperties:nN #1#2 { T , F , TF }
    {
     \prop_get:NnNTF \g__pdfmanagement_documentproperties_prop  {#1} #2
       {
        \prg_return_true:
       }
       {
        \prg_return_false:
       }
    }
\msg_new:nnn  { pdfmanagement } { show-properties }
  {
    The~following~document~properties~have~been~stored:
    #1
  }
\NewDocumentCommand\ShowDocumentProperties {}
  {
    \msg_show:nne {pdfmanagement}{show-properties}
      {
        \prop_map_function:NN \g__pdfmanagement_documentproperties_prop \msg_show_item:nn
      }
  }
%% File: l3pdfannot.dtx
\cs_if_exist:NF \bitset_new:Nn
  { \RequirePackage { l3bitset } }
\bitset_new:Nn \l_pdfannot_F_bitset
  {
    Invisible      = 1,
    Hidden         = 2,
    Print          = 3,
    NoZoom         = 4,
    NoRotate       = 5,
    NoView         = 6,
    ReadOnly       = 7,
    Locked         = 8,
    ToggleNoView   = 9,
    LockedContents = 10
  }
\bool_new:N \g__pdfannot_use_lastlink_bool
\cs_new_protected:Npn \pdfannot_box:nnnn #1 #2 #3 #4
  {
    \__pdf_backend_annotation:nnnn {#1}{#2}{#3}{#4}
    \bool_gset_false:N\g__pdfannot_use_lastlink_bool
  }
\cs_generate_variant:Nn \pdfannot_box:nnnn {nnne,nnnx}
\cs_new:Npn \pdfannot_box_ref_last:
  {
    \__pdf_backend_annotation_last:
  }

 \pdfdict_new:n   { l__pdfannot/widget }
 \pdfdict_new:n   { l__pdfannot/widget/AA }
 \pdfdict_new:n   { l__pdfannot/widget/AP }
 \pdfdict_new:n   { l__pdfannot/widget/MK }
 \pdfdict_new:n   { l__pdfannot/widget/BS }
 \pdfdict_put:nnn { l__pdfannot/widget }{ Subtype }{ /Widget }
 \hook_new_pair:nn
   {pdfannot/widget/before}
   {pdfannot/widget/after}
\cs_new_protected:Npn \pdfannot_widget_box:nnn #1 #2 #3
  {
    \hook_use:n { pdfannot/widget/before }
    \group_begin:
    \pdfmeta_standard_verify:nT
      {annot_widget_no_AA}
      {
        \pdfdict_if_empty:nF { l__pdfannot/widget/AA }
          {
            \pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l__pdfannot/widget/AA}}
            \pdfdict_put:nne { l__pdfannot/widget }
              {AA}
              {\pdf_object_ref_last:}
          }
      }
    \pdfdict_if_empty:nF { l__pdfannot/widget/AP }
      {
        \pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l__pdfannot/widget/AP}}
        \pdfdict_put:nne { l__pdfannot/widget }
             {AP}
             {\pdf_object_ref_last:}
      }
    \pdfdict_if_empty:nF { l__pdfannot/widget/MK }
      {
        \pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l__pdfannot/widget/MK}}
        \pdfdict_put:nne { l__pdfannot/widget }
             {MK}
             {\pdf_object_ref_last:}
      }
    \pdfdict_if_empty:nF { l__pdfannot/widget/BS }
      {
        \pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l__pdfannot/widget/BS}}
        \pdfdict_put:nne { l__pdfannot/widget }
             {BS}
             {\pdf_object_ref_last:}
      }
    \pdfannot_box:nnne {#1}{#2}{#3}
      {
        \pdfdict_use:n { l__pdfannot/widget}
      }
    \hook_use:n { pdfannot/widget/end }
    \group_end:
    \bool_gset_false:N\g__pdfannot_use_lastlink_bool
  }
\seq_const_from_clist:Nn \c_pdfannot_link_types_seq { URI , GoToR , Launch , GoTo, Named }
\seq_map_inline:Nn \c_pdfannot_link_types_seq
  {
    \pdfdict_new:n { l__pdfannot/link/#1 }
    \pdfdict_put:nnn { l__pdfannot/link/#1 }{ Subtype }{ /Link }
    \hook_new_pair:nn
      {pdfannot/link/#1/before}
      {pdfannot/link/#1/after}
    \hook_new_pair:nn
      {pdfannot/link/#1/begin}
      {pdfannot/link/#1/end}
   }
\cs_new_protected:Nn \pdfannot_link_off: { \__pdf_backend_link_off: }
\cs_new_protected:Nn \pdfannot_link_on:  { \__pdf_backend_link_on: }
\cs_new_protected:Nn \pdfannot_link:nnn %#1 type (URI, GoTo etc),
                                        %#2 action spec, #3 link text
  {
    \hook_use:n { pdfannot/link/#1/before}
    \mode_leave_vertical:
    \exp_args:Nee %xetex needs expansion
    \__pdf_backend_link_begin_user:nnw
      {
         \pdfdict_if_exist:nT { l__pdfannot/link/#1 }
          {
            \pdfdict_use:n { l__pdfannot/link/#1}
          }
      }
      {
        #2 %exp_not?
      }
    \bool_gset_true:N \g__pdfannot_use_lastlink_bool
    \hook_use:n { pdfannot/link/#1/begin}
    #3
    \hook_use:n { pdfannot/link/#1/end}
    \__pdf_backend_link_end:
    \bool_gset_true:N \g__pdfannot_use_lastlink_bool
    \hook_use:n { pdfannot/link/#1/after}
  }
\cs_generate_variant:Nn \pdfannot_link:nnn {nen,nxn}
\cs_new_protected:Npn \pdfannot_link_begin:nnw #1 #2 %#1 type, #2 action spec
  {
    \hook_use:n { pdfannot/link/#1/before}
    \mode_leave_vertical:
    \exp_args:Nee %xetex needs expansion
      \__pdf_backend_link_begin_user:nnw
        {
           \pdfdict_if_exist:nT { l__pdfannot/link/#1 }
            {
              \pdfdict_use:n { l__pdfannot/link/#1}
            }
        }
        { #2 }
      \bool_gset_true:N \g__pdfannot_use_lastlink_bool
      \hook_use:n { pdfannot/link/#1/begin}
  }

\cs_new_protected:Nn \pdfannot_link_end:n %#1 type, e.g. url
  {
    \hook_use:n { pdfannot/link/#1/end}
    \__pdf_backend_link_end:
    \bool_gset_true:N \g__pdfannot_use_lastlink_bool
    \hook_use:n { pdfannot/link/#1/after}
  }
\cs_generate_variant:Nn \pdfannot_link_begin:nnw {new,nxw}
\cs_new_protected:Npn \pdfannot_link_goto_begin:nw #1 %#1 destination
  {
    \pdfdict_remove:nn { l__pdfannot/link/GoTo} {Subtype}
    \hook_use:n { pdfannot/link/GoTo/before} %the backend add it too
    \mode_leave_vertical:
    \exp_args:Nee %xetex needs expansion
    \__pdf_backend_link_begin_goto:nnw
      {
        \pdfdict_use:n { l__pdfannot/link/GoTo}
      }
      { #1 }
     \bool_gset_true:N \g__pdfannot_use_lastlink_bool
    \pdfdict_put:nnn { l__pdfannot/link/GoTo} {Subtype}{GoTo}
     \hook_use:n { pdfannot/link/GoTo/begin}
  }

\cs_new_protected:Nn \pdfannot_link_goto_end:
  {
    \hook_use:n { pdfannot/link/GoTo/end}
    \__pdf_backend_link_end:
    \bool_gset_true:N \g__pdfannot_use_lastlink_bool
     \hook_use:n { pdfannot/link/GoTo/after}
  }
\cs_new:Nn \pdfannot_link_ref_last: { \__pdf_backend_link_last: }
\cs_new:Npn \pdfannot_ref_last:
  {
    \bool_if:NTF \g__pdfannot_use_lastlink_bool
      {
        \__pdf_backend_link_last:
      }
      {
        \__pdf_backend_annotation_last:
      }
  }
\cs_new_protected:Npn \pdfannot_link_margin:n #1
  {
    \__pdf_backend_link_margin:n { #1 }
  }
\cs_new_protected:Npn \pdfannot_dict_put:nnn #1 #2 #3
  {
    \pdfdict_put:nnn { l__pdfannot/#1 } { #2 }{ #3 }
  }
\cs_generate_variant:Nn \pdfannot_dict_put:nnn {nne,nnx}
\cs_new_protected:Npn \pdfannot_dict_remove:nn #1 #2
  {
    \pdfdict_remove:nn { l__pdfannot/#1 } { #2 }
  }
\cs_new_protected:Npn \pdfannot_dict_show:n #1
  {
    \pdfdict_show:n { l__pdfannot/#1 }
  }

\cs_new:Npn \pdfannot_dict_use:n #1
  {
    \pdfdict_use:n { l__pdfannot/#1 }
  }
%% File: l3pdfxform.dtx
\cs_new_protected:Npn  \pdfxform_new:nnn #1 #2 #3
  {
    \__pdf_backend_xform_new:nnnn { #1 } { #2 } {  } { #3 }
  }
\cs_new_protected:Npn \pdfxform_use:n #1
  {
    \__pdf_backend_xform_use:n { #1 }
  }
\cs_new:Npn \pdfxform_ref:n #1
  {
    \__pdf_backend_xform_ref:n { #1 }
  }

\cs_generate_variant:Nn \pdfxform_ref:n {o}
\cs_new:Npn \pdfxform_wd:n #1
  {
    \tl_use:c { c__pdf_backend_xform_wd_ \tl_to_str:n { #1 } _tl }
  }

\cs_new:Npn \pdfxform_ht:n #1
  {
    \tl_use:c { c__pdf_backend_xform_ht_ \tl_to_str:n { #1 } _tl }
  }

\cs_new:Npn \pdfxform_dp:n #1
  {
    \tl_use:c { c__pdf_backend_xform_dp_ \tl_to_str:n { #1 } _tl }
  }
%% File: l3pdfmeta.dtx


\msg_new:nnn  {pdf }{unknown-standard}{The~standard~'#1'~is~unknown~and~has~been~ignored}
\msg_new:nnn  {pdf }{wrong-pdfversion}
  {PDF~version~#1~is~too~#2~for~standard~'#3'.}
\tl_new:N  \l__pdfmeta_tmpa_tl
\tl_new:N  \l__pdfmeta_tmpb_tl
\str_new:N \l__pdfmeta_tmpa_str
\str_new:N \g__pdfmeta_tmpa_str
\seq_new:N \l__pdfmeta_tmpa_seq
\seq_new:N \l__pdfmeta_tmpb_seq
\prop_new:N \g__pdfmeta_standard_prop
\cs_new:Npn \pdfmeta_standard_item:n #1
 {
   \prop_item:Nn \g__pdfmeta_standard_prop {#1}
 }
\cs_new_protected:Npn \pdfmeta_standard_get:nN #1 #2
 {
   \prop_get:NnN \g__pdfmeta_standard_prop {#1} #2
 }
\prg_new_conditional:Npnn \pdfmeta_standard_verify:n #1 {T,F,TF}
  {
     \prop_if_in:NnTF \g__pdfmeta_standard_prop {#1}
       {
         \prg_return_false:
       }
       {
         \prg_return_true:
       }
  }
\prg_new_protected_conditional:Npnn \pdfmeta_standard_verify:nn #1 #2  {T,F,TF}
  {
    \prop_if_in:NnTF \g__pdfmeta_standard_prop {#1}
      {
        \cs_if_exist:cTF {__pdfmeta_standard_verify_handler_#1:nn}
          {
            \exp_args:Nnne
            \use:c
              {__pdfmeta_standard_verify_handler_#1:nn}
              { #2 }
              { \prop_item:Nn \g__pdfmeta_standard_prop {#1} }
          }
          {
            \prg_return_false:
          }
      }
      {
        \prg_return_true:
      }
   }
\cs_new_protected:Npn \__pdfmeta_standard_verify_handler_min_pdf_version:nn #1 #2
 {
   \pdf_version_compare:NnTF <
     { #2 }
     {\prg_return_false:}
     {\prg_return_true:}
 }
\cs_new_protected:Npn \__pdfmeta_standard_verify_handler_max_pdf_version:nn #1 #2
 {
   \pdf_version_compare:NnTF >
     { #2 }
     {\prg_return_false:}
     {\prg_return_true:}
 }

\cs_new_protected:Npn \__pdfmeta_standard_verify_handler_named_actions:nn #1 #2
 {
   \tl_if_in:nnTF { #2 }{ #1 }
     {\prg_return_true:}
     {\prg_return_false:}
 }
\cs_new_protected:Npn \__pdfmeta_standard_verify_handler_annot_action_A:nn #1 #2
 {
   \tl_if_in:nnTF { #2 }{ #1 }
     {\prg_return_true:}
     {\prg_return_false:}
 }
\cs_new_protected:Npn \__pdfmeta_standard_verify_handler_outputintent_subtype:nn #1 #2
 {
   \tl_if_eq:nnTF { #2 }{ #1 }
     {\prg_return_true:}
     {\prg_return_false:}
 }
\cs_new_protected:Npn \__pdfmeta_verify_pdfa_annot_flags:
  {
    \bitset_set_true:Nn  \l_pdfannot_F_bitset {Print}
    \bitset_set_false:Nn \l_pdfannot_F_bitset {Hidden}
    \bitset_set_false:Nn \l_pdfannot_F_bitset {Invisible}
    \bitset_set_false:Nn \l_pdfannot_F_bitset {NoView}
    \pdfannot_dict_put:nnn {link/URI}{F}{ \bitset_to_arabic:N \l_pdfannot_F_bitset }
    \pdfannot_dict_put:nnn {link/GoTo}{F}{ \bitset_to_arabic:N \l_pdfannot_F_bitset }
    \pdfannot_dict_put:nnn {link/GoToR}{F}{ \bitset_to_arabic:N \l_pdfannot_F_bitset }
    \pdfannot_dict_put:nnn {link/Launch}{F}{ \bitset_to_arabic:N \l_pdfannot_F_bitset }
    \pdfannot_dict_put:nnn {link/Named}{F}{ \bitset_to_arabic:N \l_pdfannot_F_bitset }
  }
\hook_gput_code:nnn {begindocument} {pdf}
  {
    \pdfmeta_standard_verify:nF { annot_flags }
     { \__pdfmeta_verify_pdfa_annot_flags: }
    \pdfmeta_standard_verify:nF { Trailer_no_Info }
     { \__pdf_backend_omit_info:n {1} }
    \pdfmeta_standard_verify:nF { no_CharSet }
     { \__pdf_backend_omit_charset:n {1} }
    \pdfmeta_standard_verify:nnF { min_pdf_version }
     { \pdf_version: }
     { \msg_warning:nneee {pdf}{wrong-pdfversion}
       {\pdf_version:}{low}
       {
        \pdfmeta_standard_item:n{type}
        -
        \pdfmeta_standard_item:n{level}
       }
     }
    \pdfmeta_standard_verify:nnF { max_pdf_version }
     { \pdf_version: }
     { \msg_warning:nneee {pdf}{wrong-pdfversion}
       {\pdf_version:}{high}
       {
        \pdfmeta_standard_item:n{type}
        -
        \pdfmeta_standard_item:n{level}
       }
     }
  }
\prop_new:c { g__pdfmeta_standard_pdf/A-1B_prop }
\prop_gset_from_keyval:cn { g__pdfmeta_standard_pdf/A-1B_prop }
  {
    ,name             = pdf/A-1B
    ,type             = A
    ,level            = 1
    ,conformance      = B
    ,year             = 2005
    ,min_pdf_version  = 1.4        %minimum
    ,max_pdf_version  = 1.4        %minimum
    ,no_encryption    =
    ,no_external_content =  % no F, FFilter, or FDecodeParms in stream dicts
    ,no_embed_content = % no EF key in filespec, no /Type/EmbeddedFiles
    ,max_string_size  = 65535
    ,max_array_size   = 8191
    ,max_dict_size    = 4095
    ,max_obj_num      = 8388607
    ,max_nest_qQ      = 28
    ,named_actions    = {NextPage, PrevPage, FirstPage, LastPage}
    ,annot_flags      =
    %booleans. Only the existence of the key matter.
    %If the entry is added it means a requirements is there
    %(in most cases "don't use ...")
    %
    %===============
    % Rule 6.1.13-1 CosDocument, isOptionalContentPresent == false
      ,Catalog_no_OCProperties =
    %===============
    % Rule 6.6.1-1: PDAction, S == "GoTo" || S == "GoToR" || S == "Thread"
    %               || S == "URI" || S == "Named" || S == "SubmitForm"
    % means: no /S/Launch, /S/Sound, /S/Movie, /S/ResetForm, /S/ImportData,
    %        /S/JavaScript, /S/Hide
      ,annot_action_A        = {GoTo,GoToR,Thread,URI,Named,SubmitForm}
    %===============
    % Rule 6.6.2-1: PDAnnot, Subtype != "Widget" || AA_size == 0
    % means: no AA dictionary
      ,annot_widget_no_AA      =
    %===============
    % Rule 6.9-2: PDAnnot, Subtype != "Widget" || (A_size == 0 && AA_size == 0)
    % (looks like a tightening of the previous rule)
      ,annot_widget_no_A_AA    =
    %===============
    % Rule 6.9-1 PDAcroForm, NeedAppearances == null || NeedAppearances == false
    ,form_no_NeedAppearances =
    %===============
    %Rule 6.9-3 PDFormField, AA_size == 0
    ,form_no_AA              =
    %===============
    % to be continued https://docs.verapdf.org/validation/pdfa-part1/
    % - Outputintent/colorprofiles requirements
    % an outputintent should be loaded and is unique.
    ,outputintent_A         = {GTS_PDFA1}
    % - no Alternates key in image dictionaries
    % - no OPI, Ref, Subtype2 with PS key in xobjects
    % - Interpolate  = false in images
    % - no TR, TR2 in ExtGstate
  }

\prop_new:c { g__pdfmeta_standard_pdf/A-2B_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-2B_prop }
  { g__pdfmeta_standard_pdf/A-1B_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2B_prop }{name}{pdf/A-2B}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2B_prop }{year}{2011}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2B_prop }{level}{2}
\prop_gremove:cn
  { g__pdfmeta_standard_pdf/A-2B_prop }
  { embed_content}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2B_prop }{max_pdf_version}{1.7}
\prop_new:c { g__pdfmeta_standard_pdf/A-2U_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-2U_prop }
  { g__pdfmeta_standard_pdf/A-2B_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2U_prop }{name}{pdf/A-2U}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2U_prop }{conformance}{U}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2U_prop }{unicode}{}

\prop_new:c { g__pdfmeta_standard_pdf/A-2A_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-2A_prop }
  { g__pdfmeta_standard_pdf/A-2B_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2A_prop }{name}{pdf/A-2A}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2A_prop }{conformance}{A}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-2A_prop }{tagged}{}

\prop_new:c { g__pdfmeta_standard_pdf/A-3B_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-3B_prop }
  { g__pdfmeta_standard_pdf/A-2B_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3B_prop }{name}{pdf/A-3B}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3B_prop }{year}{2012}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3B_prop }{level}{3}
\prop_gremove:cn
  { g__pdfmeta_standard_pdf/A-3B_prop }
  { embed_content}
\prop_new:c { g__pdfmeta_standard_pdf/A-3U_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-3U_prop }
  { g__pdfmeta_standard_pdf/A-3B_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3U_prop }{name}{pdf/A-3U}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3U_prop }{conformance}{U}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3U_prop }{unicode}{}

\prop_new:c { g__pdfmeta_standard_pdf/A-3A_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-3A_prop }
  { g__pdfmeta_standard_pdf/A-3B_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3A_prop }{name}{pdf/A-3A}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3A_prop }{conformance}{A}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-3A_prop }{tagged}{}

\prop_new:c { g__pdfmeta_standard_pdf/A-4_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-4_prop }
  { g__pdfmeta_standard_pdf/A-3U_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4_prop }{name}{pdf/A-4}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4_prop }{level}{4}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4_prop }{min_pdf_version}{2.0}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4_prop }{year}{2020}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4_prop }{no_CharSet}{}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4_prop }{Trailer_no_Info}{}
\prop_gremove:cn
  { g__pdfmeta_standard_pdf/A-4_prop }{conformance}
\prop_gremove:cn
  { g__pdfmeta_standard_pdf/A-4_prop }{max_pdf_version}

\prop_new:c { g__pdfmeta_standard_pdf/A-4F_prop }
\prop_gset_eq:cc
  { g__pdfmeta_standard_pdf/A-4F_prop }
  { g__pdfmeta_standard_pdf/A-4_prop }
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4F_prop }{conformance}{F}
\prop_gput:cnn
  { g__pdfmeta_standard_pdf/A-4F_prop }{Catalog_EmbeddedFiles}{}
\AddToHook{begindocument/end}
{
  \pdfmeta_standard_verify:nF{Catalog_EmbeddedFiles}
   {
    \tl_gput_right:Nn\g__kernel_pdfmanagement_end_run_code_tl
     {
       \bool_if:NT \g__pdfmanagement_active_bool
        {
         \pdfdict_if_empty:nT { g__pdf_Core/Catalog/Names/EmbeddedFiles }
          {
            \group_begin:
            \pdfdict_put:nne {l_pdffile/Filespec} {Desc}{(note~about~PDF/A-4F)}
            \pdfdict_put:nnn { l_pdffile/Filespec }{AFRelationship} { /Unspecified }
            \pdffile_embed_stream:nnN {PDF~standard~A-4F~requires~a~file}{readme.txt}\l__pdfmeta_tmpa_tl
            \exp_args:Nne \__pdf_backend_Names_gpush:nn{EmbeddedFiles}{(readme)~\l__pdfmeta_tmpa_tl}
            \group_end:
          }
       }
     }
   }
}
\prop_new:N \g__pdfmeta_outputintents_prop
\keys_define:nn { document / metadata }
  {
    colorprofiles .code:n =
     {
       \keys_set:nn { document / metadata / colorprofiles }{#1}
     }
  }
\keys_define:nn { document / metadata / colorprofiles }
 {
   ,A .code:n =
      {
        \tl_if_blank:nF {#1}
          {
            \prop_gput:Nnn \g__pdfmeta_outputintents_prop
             { GTS_PDFA1  } {#1}
          }
      }
   ,a .code:n =
      {
        \tl_if_blank:nF {#1}
          {
            \prop_gput:Nnn \g__pdfmeta_outputintents_prop
              { GTS_PDFA1  } {#1}
          }
      }
   ,X .code:n =
      {
        \tl_if_blank:nF {#1}
          {
             \prop_gput:Nnn \g__pdfmeta_outputintents_prop
              { GTS_PDFX  } {#1}
          }
      }
   ,x .code:n =
      {
        \tl_if_blank:nF {#1}
          {
            \prop_gput:Nnn \g__pdfmeta_outputintents_prop
              { GTS_PDFX  } {#1}
          }
      }
   ,unknown .code:n =
     {
       \tl_if_blank:nF {#1}
          {
           \exp_args:NNo
            \prop_gput:Nnn \g__pdfmeta_outputintents_prop
              { \l_keys_key_str  } {#1}
          }
     }
 }
\pdfdict_new:n   {l_pdfmeta/outputintent}
\pdfdict_put:nnn {l_pdfmeta/outputintent}
  {Type}{/OutputIntent}
\prop_const_from_keyval:cn { c__pdfmeta_colorprofile_sRGB.icc}
  {
    ,OutputConditionIdentifier=IEC~sRGB
    ,Info=IEC~61966-2.1~Default~RGB~colour~space~-~sRGB
    ,RegistryName=http://www.iec.ch
    ,N = 3
  }
\prop_const_from_keyval:cn { c__pdfmeta_colorprofile_FOGRA39L_coated.icc}
  {
    ,OutputConditionIdentifier=FOGRA39L~Coated
    ,Info={Offset~printing,~according~to~ISO~12647-2:2004/Amd~1,~OFCOM,~ %
           paper~type~1~or~2~=~coated~art,~115~g/m2,~tone~value~increase~
           curves~A~(CMY)~and~B~(K)}
    ,RegistryName=http://www.fogra.org
    ,N = 4
  }
\cs_new_protected:Npn \__pdfmeta_embed_colorprofile:n #1%#1 file name
  {
    \pdf_object_if_exist:nF { __color_icc_ #1 }
      {
        \pdf_object_new:n  { __color_icc_ #1 }
        \pdf_object_write:nne { __color_icc_ #1 } { fstream }
         {
           {/N\c_space_tl
             \prop_item:cn{c__pdfmeta_colorprofile_#1}{N}
           }
           {#1}
         }
      }
  }

\cs_new_protected:Npn \__pdfmeta_write_outputintent:nn #1 #2 %#1 file name, #2 subtype
  {
    \group_begin:
     \pdfdict_put:nne {l_pdfmeta/outputintent}{S}{/\str_convert_pdfname:n{#2}}
     \pdfdict_put:nne {l_pdfmeta/outputintent}
       {DestOutputProfile}
       {\pdf_object_ref:n{ __color_icc_ #1 }}
     \clist_map_inline:nn { OutputConditionIdentifier, Info, RegistryName }
       {
         \prop_get:cnNT
          { c__pdfmeta_colorprofile_#1}
          { ##1 }
          \l__pdfmeta_tmpa_tl
          {
            \pdf_string_from_unicode:nVN {utf8/string}\l__pdfmeta_tmpa_tl\l__pdfmeta_tmpa_str
            \pdfdict_put:nne
              {l_pdfmeta/outputintent}{##1}{\l__pdfmeta_tmpa_str}
          }
       }
     \pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n {l_pdfmeta/outputintent} }
     \pdfmanagement_add:nne {Catalog}{OutputIntents}{\pdf_object_ref_last:}
    \group_end:
  }

\AddToHook{begindocument/end}
  {
    \pdfmeta_standard_verify:nTF {outputintent_A}
      {
        \prop_map_inline:Nn \g__pdfmeta_outputintents_prop
           {
             \prop_if_exist:cTF {c__pdfmeta_colorprofile_#2}
               {
                 \__pdfmeta_embed_colorprofile:n
                  {#2}
                 \__pdfmeta_write_outputintent:nn
                  {#2}
                  {#1}
               }
               {
                \msg_warning:nnn{pdfmeta}{colorprofile-undefined}{#2}
               }
           }
      }
      {
         \exp_args:NNe
         \prop_if_in:NnF
           \g__pdfmeta_outputintents_prop
           { \pdfmeta_standard_item:n { outputintent_A } }
           {
             \exp_args:NNe
             \prop_gput:Nnn
               \g__pdfmeta_outputintents_prop
               { \pdfmeta_standard_item:n { outputintent_A } }
               { sRGB.icc }
           }
         \exp_args:NNe
         \prop_get:NnN
           \g__pdfmeta_outputintents_prop
           { \pdfmeta_standard_item:n { outputintent_A } }
           \l__pdfmeta_tmpb_tl
         \prop_if_exist:cTF {c__pdfmeta_colorprofile_\l__pdfmeta_tmpb_tl}
          {
            \exp_args:NV \__pdfmeta_embed_colorprofile:n \l__pdfmeta_tmpb_tl
            \prop_map_inline:Nn \g__pdfmeta_outputintents_prop
              {
                \exp_args:NV
                 \__pdfmeta_write_outputintent:nn
                   \l__pdfmeta_tmpb_tl
                   { #1 }
              }
          }
          {
            \msg_warning:nne{pdfmeta}{colorprofile-undefined}{\l__pdfmeta_tmpb_tl}
          }
       }
   }
\cs_new_protected:Npn \pdfmeta_set_regression_data:
   { \__pdf_backend_set_regression_data: }

\bool_new:N\g__pdfmeta_xmp_bool
\bool_gset_true:N \g__pdfmeta_xmp_bool
\hook_gput_code:nnn{pdfmanagement/add}{pdfmanagement}
  {
   \pdfmanagement_add:nne {Info}{Producer}{(\c_sys_engine_exec_str-\c_sys_engine_version_str)}
   \pdfmanagement_add:nne {Info}{Creator}{(LaTeX)}
  }
\keys_define:nn { document / metadata }
 {
   _pdfstandard / X-4 .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-4}},
   _pdfstandard / X-4p .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-4p}},
   _pdfstandard / X-5g .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-5g}},
   _pdfstandard / X-5n .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-5n}},
   _pdfstandard / X-5pg .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-5pg}},
   _pdfstandard / X-6 .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-6p}},
   _pdfstandard / X-6n .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-6n}},
   _pdfstandard / X-6p .code:n =
    {\AddToDocumentProperties [document]{pdfstandard-X}{PDF/X-6p}},
   _pdfstandard / UA-1 .code:n =
    {
     \AddToDocumentProperties [document]{pdfstandard-UA}{{1}{}}
    },
   _pdfstandard / UA-2 .code:n =
    {
      \AddToDocumentProperties [document]{pdfstandard-UA}{{2}{2024}}
      \AddToHook{begindocument/before}
       {\prop_gput:Nnn \g__pdfmeta_standard_prop {Trailer_no_Info}{}}
      \AddToHook{begindocument/before}
       {
         \__pdfmeta_xmp_wtpdf_accessibility_declaration:
         \__pdfmeta_xmp_wtpdf_reuse_declaration:
       }
    },
   xmp  .choice:,
   xmp / true  .code:n = { \bool_gset_true:N \g__pdfmeta_xmp_bool },
   xmp / false .code:n = { \bool_gset_false:N \g__pdfmeta_xmp_bool},
   xmp .default:n = true,
   xmp / wtpdf .code:n =
    {
      \keys_set:nn {__pdfmeta/xmp}{#1}
    },
 }
\keys_define:nn {__pdfmeta/xmp}
 {
   reuse .choice:,
   reuse / true .code:n = \__pdfmeta_xmp_wtpdf_reuse_declaration:,
   reuse / false .code:n =
    {
      \cs_set_eq:NN \__pdfmeta_xmp_wtpdf_reuse_declaration: \prg_do_nothing:
    },
   accessibility .choice:,
   accessibility / true .code:n = \__pdfmeta_xmp_wtpdf_accessibility_declaration:,
   accessibility /false .code:n =
    {
      \cs_set_eq:NN \__pdfmeta_xmp_wtpdf_accessibility_declaration: \prg_do_nothing:
    },
  }
\bool_new:N \g__pdfmeta_xmp_export_bool
\str_new:N  \g__pdfmeta_xmp_export_str

\keys_define:nn { document / metadata }
  {
    ,debug / xmp-export .choice:
    ,debug / xmp-export / true .code:n=
      {
        \bool_gset_true:N \g__pdfmeta_xmp_export_bool
        \str_gset_eq:NN \g__pdfmeta_xmp_export_str \c_sys_jobname_str
      }
    ,debug / xmp-export / false .code:n =
      {
        \bool_gset_false:N \g__pdfmeta_xmp_export_bool
      }
    ,debug / xmp-export /unknown .code:n =
      {
        \bool_gset_true:N \g__pdfmeta_xmp_export_bool
        \str_gset:Nn \g__pdfmeta_xmp_export_str { #1 }
      }
    ,debug / xmp-export .default:n = true
  }
\msg_new:nnn{pdfmeta}{namespace-defined}{The~xmlns~namespace~`#1`~is~already~declared}
\msg_new:nnn{pdfmeta}{colorprofile-undefined}{The~colorprofile~`#1`~is~unknown}
\bool_lazy_or:nnTF
  { \sys_if_engine_luatex_p: }
  { \sys_if_engine_xetex_p: }
  {
    \cs_new:Npn \__pdfmeta_xmp_generate_bom:
      { \char_generate:nn {"FEFF}{12} }
  }
  {
    \cs_new:Npn \__pdfmeta_xmp_generate_bom:
      {
        \char_generate:nn {"EF}{12}
        \char_generate:nn {"BB}{12}
        \char_generate:nn {"BF}{12}
      }
  }
\int_new:N  \l__pdfmeta_xmp_indent_int
\cs_new:Npn \__pdfmeta_xmp_indent:
  {
    \iow_newline:
    \prg_replicate:nn {\l__pdfmeta_xmp_indent_int}{\c_space_tl}
  }

\cs_new:Npn \__pdfmeta_xmp_indent:n #1
  {
    \iow_newline:
    \prg_replicate:nn {#1}{\c_space_tl}
  }

\cs_new_protected:Npn \__pdfmeta_xmp_incr_indent:
  {
    \int_incr:N \l__pdfmeta_xmp_indent_int
  }

\cs_new_protected:Npn \__pdfmeta_xmp_decr_indent:
  {
    \int_decr:N \l__pdfmeta_xmp_indent_int
  }
\regex_new:N \l__pdfmeta_xmp_date_regex
\regex_set:Nn \l__pdfmeta_xmp_date_regex
 {D:(\d{4})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?([Z\+\-])?(?:(\d{2})\')?(?:(\d{2})\')?}
\cs_new_protected:Npn \__pdfmeta_xmp_date_split:nN #1 #2 %#1 date, #2 seq
  {
    \regex_split:NnN \l__pdfmeta_xmp_date_regex {#1} #2
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_date_split:nN {VN,eN}

\cs_new:Npn\__pdfmeta_xmp_print_date:N #1 % seq
  {
    \tl_if_blank:eTF { \seq_item:Nn #1 {1} }
     {
       \seq_item:Nn #1 {2} %year
        -
       \seq_item:Nn #1 {3} %month
        -
       \seq_item:Nn #1 {4} % day
       \tl_if_blank:eF
         { \seq_item:Nn #1 {5} }
         { T \seq_item:Nn #1 {5} } %hour
       \tl_if_blank:eF
         { \seq_item:Nn #1 {6} }
         { : \seq_item:Nn #1 {6} } %minutes
       \tl_if_blank:eF
         { \seq_item:Nn #1 {7} }
         { : \seq_item:Nn #1 {7} } %seconds
       \seq_item:Nn #1 {8}  %Z,+,-
       \seq_item:Nn #1 {9}
       \tl_if_blank:eF
         { \seq_item:Nn #1 {10} }
         { : \seq_item:Nn #1 {10} }
      }
      {
        \seq_item:Nn #1 {1}
      }
  }
\tl_new:N  \l__pdfmeta_xmp_currentdate_tl
\seq_new:N \l__pdfmeta_xmp_currentdate_seq
\cs_new_protected:Npn \__pdfmeta_xmp_date_get:nNN #1 #2 #3
  %#1 property, #2 tl var with PDF date, #3 seq for splitted date
  {
    \tl_set:Ne #2 { \GetDocumentProperties{#1} }
    \tl_if_blank:VTF #2
      {
        \seq_set_eq:NN #3 \l__pdfmeta_xmp_currentdate_seq
        \tl_set_eq:NN  #2 \l__pdfmeta_xmp_currentdate_tl
      }
      {
        \__pdfmeta_xmp_date_split:VN #2 #3
      }
  }
\cs_new_protected:Npn \__pdfmeta_xmp_create_uuid:nN #1 #2
  {
    \str_set:Ne#2 {\str_lowercase:f{\tex_mdfivesum:D{#1}}}
    \str_set:Ne#2
      { uuid:
        \str_range:Nnn #2{1}{8}
        -\str_range:Nnn#2{9}{12}
        -4\str_range:Nnn#2{13}{15}
        -8\str_range:Nnn#2{16}{18}
        -\str_range:Nnn#2{19}{30}
      }
  }
\cs_new_protected:Npn \__pdfmeta_xmp_sanitize:nN #1 #2
  {
    \group_begin:
     \text_declare_purify_equivalent:Nn \& {\tl_to_str:N & }
     \text_declare_purify_equivalent:Nn \texttilde {\c_tilde_str}
     \tl_set:Ne \l__pdfmeta_tmpa_tl { \text_purify:n {#1} }
     \str_gset:Ne \g__pdfmeta_tmpa_str { \tl_to_str:N \l__pdfmeta_tmpa_tl }
     \str_greplace_all:Nnn\g__pdfmeta_tmpa_str {&}{&amp;}
     \str_greplace_all:Nnn\g__pdfmeta_tmpa_str {<}{&lt;}
     \str_greplace_all:Nnn\g__pdfmeta_tmpa_str {>}{&gt;}
     \str_greplace_all:Nnn\g__pdfmeta_tmpa_str {"}{&quot;}
    \group_end:
     \str_set_eq:NN #2 \g__pdfmeta_tmpa_str
  }

\cs_generate_variant:Nn\__pdfmeta_xmp_sanitize:nN {VN}
\tl_new:N \l__pdfmeta_xmp_doclang_tl
\tl_new:N \l__pdfmeta_xmp_metalang_tl
\regex_new:N\l__pdfmeta_xmp_lang_regex
\regex_set:Nn\l__pdfmeta_xmp_lang_regex {\A\[([A-Za-z\-]+)\](.*)}
\cs_new_protected:Npn \__pdfmeta_xmp_lang_get:nNN #1 #2 #3
  {
    \regex_extract_once:NnN \l__pdfmeta_xmp_lang_regex {#1}\l__pdfmeta_tmpa_seq
    \seq_if_empty:NTF \l__pdfmeta_tmpa_seq
      {
        \tl_set:Nn #2 \l__pdfmeta_xmp_metalang_tl
        \tl_set:Nn #3 {#1}
      }
      {
        \tl_set:Ne #2 {\seq_item:Nn\l__pdfmeta_tmpa_seq{2}}
        \tl_set:Ne #3 {\seq_item:Nn\l__pdfmeta_tmpa_seq{3}}
      }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_lang_get:nNN {eNN,VNN}

\tl_new:N \g__pdfmeta_xmp_packet_tl
\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_chunk:n #1
  {
    \tl_gput_right:Ne\g__pdfmeta_xmp_packet_tl
      {
        \__pdfmeta_xmp_indent:  \exp_not:n{#1}
      }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_chunk:n {e}

\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_chunk:nN #1 #2
  {
    \tl_put_right:Ne#2
      {
        \__pdfmeta_xmp_indent:  \exp_not:n{#1}
      }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_chunk:nN {eN}

\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_open:nn #1 #2 %#1 prefix #2 name
  {
    \__pdfmeta_xmp_add_packet_chunk:n {<#1:#2>}
    \__pdfmeta_xmp_incr_indent:
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_open:nn  {ne}

\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_open_attr:nnn #1 #2 #3
  %#1 prefix #2 name #3 attr
  {
    \__pdfmeta_xmp_add_packet_chunk:n {<#1:#2~#3>}
    \__pdfmeta_xmp_incr_indent:
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_open_attr:nnn  {nne}

\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_close:nn #1 #2 %#1 prefix #2:name
  {
    \__pdfmeta_xmp_decr_indent:
    \__pdfmeta_xmp_add_packet_chunk:n {</#1:#2>}
  }
\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_line:nnn #1 #2 #3
 %#1 prefix #2 name #3 content
  {
    \tl_if_blank:nF {#3}
     {
      \__pdfmeta_xmp_sanitize:nN {#3}\l__pdfmeta_tmpa_str
      \__pdfmeta_xmp_add_packet_chunk:e {<#1:#2>\l__pdfmeta_tmpa_str</#1:#2>}
     }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_line:nnn {nne,nnV,nee}
\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_line:nnnN #1 #2 #3 #4
 %#1 prefix #2 name #3 content #4 tl_var to prebuilt.
  {
    \tl_if_blank:nF {#3}
     {
      \__pdfmeta_xmp_sanitize:nN {#3}\l__pdfmeta_tmpa_str
      \__pdfmeta_xmp_add_packet_chunk:eN {<#1:#2>\l__pdfmeta_tmpa_str</#1:#2>} #4
     }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_line:nnnN {nneN}
\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_line_attr:nnnn #1 #2 #3 #4
 %#1 prefix #2 name #3 attribute #4 content
  {
    \tl_if_blank:nF {#4}
     {
      \__pdfmeta_xmp_sanitize:nN {#4}\l__pdfmeta_tmpa_str
      \__pdfmeta_xmp_add_packet_chunk:e {<#1:#2~#3>\l__pdfmeta_tmpa_str</#1:#2>}
     }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_line_attr:nnnn {nnee,nneV}
 \cs_new_protected:Npn \__pdfmeta_xmp_add_packet_line_default:nnnn #1 #2 #3 #4
   % #1 prefix #2 name #3 default #4 content
   {
     \tl_if_blank:nTF { #4 }
      {
       \tl_set:Nn  \l__pdfmeta_tmpa_tl  {#3}
      }
      {
        \tl_set:Nn \l__pdfmeta_tmpa_tl  {#4}
      }
     \__pdfmeta_xmp_add_packet_line:nnV {#1}{#2}\l__pdfmeta_tmpa_tl
   }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_line_default:nnnn {nnee}
\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_list_simple:nnnn #1 #2 #3 #4
  %#1 prefix, #2 name,  #3 type (Seq/Bag/Alt) #4 a clist
  {
    \clist_if_empty:nF { #4 }
      {
        \__pdfmeta_xmp_add_packet_open:nn {#1}{#2}
         \__pdfmeta_xmp_add_packet_open:nn {rdf}{#3}
          \clist_map_inline:nn {#4}
            {
              \__pdfmeta_xmp_add_packet_line:nnn
               {rdf}{li}{##1}
            }
         \__pdfmeta_xmp_add_packet_close:nn{rdf}{#3}
        \__pdfmeta_xmp_add_packet_close:nn {#1}{#2}
     }
   }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_list_simple:nnnn {nnnV,nnne}
\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_list:nnnn #1 #2 #3 #4
  %#1 prefix, #2 name,  #3 type (Seq/Bag/Alt) #4 a clist
  {
    \clist_if_empty:nF { #4 }
      {
        \__pdfmeta_xmp_add_packet_open:nn {#1}{#2}
         \__pdfmeta_xmp_add_packet_open:nn {rdf}{#3}
          \clist_map_inline:nn {#4}
            {
              \__pdfmeta_xmp_lang_get:nNN {##1}\l__pdfmeta_tmpa_tl\l__pdfmeta_tmpb_tl
              \tl_if_eq:eeTF{\l__pdfmeta_tmpa_tl}{\l__pdfmeta_xmp_metalang_tl}
                {
                  \__pdfmeta_xmp_add_packet_line_attr:nneV
                   {rdf}{li}{xml:lang="x-default" }\l__pdfmeta_tmpb_tl
                }
                {
                  \__pdfmeta_xmp_add_packet_line_attr:nneV
                   {rdf}{li}{xml:lang="\l__pdfmeta_tmpa_tl" }\l__pdfmeta_tmpb_tl
                }
            }
         \__pdfmeta_xmp_add_packet_close:nn{rdf}{#3}
        \__pdfmeta_xmp_add_packet_close:nn {#1}{#2}
     }
   }
\cs_generate_variant:Nn \__pdfmeta_xmp_add_packet_list:nnnn {nnne}
\cs_new_protected:Npn \__pdfmeta_xmp_build_packet:
  {
   \tl_set:Ne \l__pdfmeta_xmp_doclang_tl  {\GetDocumentProperties{document/lang}}
   \tl_set:Ne \l__pdfmeta_xmp_metalang_tl {\GetDocumentProperties{hyperref/pdfmetalang}}
   \tl_if_blank:VT \l__pdfmeta_xmp_metalang_tl
    { \cs_set_eq:NN \l__pdfmeta_xmp_metalang_tl\l__pdfmeta_xmp_doclang_tl}
   \__pdfmeta_xmp_build_iptc_data:N \l__pdfmeta_xmp_iptc_data_tl
   \tl_if_empty:NT \l__pdfmeta_xmp_iptc_data_tl
     {
       \seq_remove_all:Nn \l__pdfmeta_xmp_schema_seq { Iptc4xmpCore }
     }
     \__pdfmeta_xmp_add_packet_chunk:e
      {<?xpacket~begin="\__pdfmeta_xmp_generate_bom:"~id="W5M0MpCehiHzreSzNTczkc9d"?>}
     \__pdfmeta_xmp_add_packet_open:nn{x}{xmpmeta~xmlns:x="adobe:ns:meta/"}
      \__pdfmeta_xmp_add_packet_open:ne{rdf}
        {RDF~xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns\c_hash_str"}
       \__pdfmeta_xmp_add_packet_open_attr:nne
         {rdf}{Description}{rdf:about="" \g__pdfmeta_xmp_xmlns_tl}
        \__pdfmeta_xmp_add_packet_open:nn{pdfaExtension}{schemas}
         \__pdfmeta_xmp_add_packet_open:nn {rdf}{Bag}
           \seq_map_inline:Nn \l__pdfmeta_xmp_schema_seq
              {
                \tl_use:c { g__pdfmeta_xmp_schema_##1_tl }
              }
         \__pdfmeta_xmp_add_packet_close:nn {rdf}{Bag}
        \__pdfmeta_xmp_add_packet_close:nn {pdfaExtension}{schemas}
    % data
        \__pdfmeta_xmp_build_pdf:
        \__pdfmeta_xmp_build_xmpRights:
        \__pdfmeta_xmp_build_standards: %pdfaid,pdfxid,pdfuaid
        \__pdfmeta_xmp_build_pdfd:
        \__pdfmeta_xmp_build_dc:
        \__pdfmeta_xmp_build_photoshop:
        \__pdfmeta_xmp_build_xmp:
        \__pdfmeta_xmp_build_xmpMM:
        \__pdfmeta_xmp_build_prism:
        \__pdfmeta_xmp_build_iptc:
        \__pdfmeta_xmp_build_user: %user additions
    % end
      \__pdfmeta_xmp_add_packet_close:nn {rdf}{Description}
     \__pdfmeta_xmp_add_packet_close:nn {rdf}{RDF}
    \__pdfmeta_xmp_add_packet_close:nn {x}{xmpmeta}
    \int_set:Nn  \l__pdfmeta_xmp_indent_int{20}
    \prg_replicate:nn{10}{\__pdfmeta_xmp_add_packet_chunk:n {}}
    \int_zero:N \l__pdfmeta_xmp_indent_int
    \__pdfmeta_xmp_add_packet_chunk:n {<?xpacket~end="w"?>}
 }


\str_new:N  \g__pdfmeta_xmp_xmlns_tl
\prop_new:N \g__pdfmeta_xmp_xmlns_prop
\cs_new_protected:Npn \__pdfmeta_xmp_xmlns_new:nn #1 #2
  {
    \prop_gput:Nnn \g__pdfmeta_xmp_xmlns_prop {#1}{#2}
    \tl_gput_right:Ne \g__pdfmeta_xmp_xmlns_tl
      {
        \__pdfmeta_xmp_indent:n{4} xmlns:\exp_not:n{#1="#2"}
      }
  }
\cs_generate_variant:Nn \__pdfmeta_xmp_xmlns_new:nn {ne}
\__pdfmeta_xmp_xmlns_new:nn {pdf}      {http://ns.adobe.com/pdf/1.3/}
\__pdfmeta_xmp_xmlns_new:nn {xmpRights}{http://ns.adobe.com/xap/1.0/rights/}
\__pdfmeta_xmp_xmlns_new:nn {dc}       {http://purl.org/dc/elements/1.1/}
\__pdfmeta_xmp_xmlns_new:nn {photoshop}{http://ns.adobe.com/photoshop/1.0/}
\__pdfmeta_xmp_xmlns_new:nn {xmp}      {http://ns.adobe.com/xap/1.0/}
\__pdfmeta_xmp_xmlns_new:nn {xmpMM}    {http://ns.adobe.com/xap/1.0/mm/}
\__pdfmeta_xmp_xmlns_new:ne {stEvt}
  {http://ns.adobe.com/xap/1.0/sType/ResourceEvent\c_hash_str}
\__pdfmeta_xmp_xmlns_new:nn {pdfaid}   {http://www.aiim.org/pdfa/ns/id/}
\__pdfmeta_xmp_xmlns_new:nn {pdfuaid}  {http://www.aiim.org/pdfua/ns/id/}
\__pdfmeta_xmp_xmlns_new:nn {pdfx}     {http://ns.adobe.com/pdfx/1.3/}
\__pdfmeta_xmp_xmlns_new:nn {pdfxid}   {http://www.npes.org/pdfx/ns/id/}
\__pdfmeta_xmp_xmlns_new:nn {prism}    {http://prismstandard.org/namespaces/basic/3.0/}
\__pdfmeta_xmp_xmlns_new:ne {stFnt}    {http://ns.adobe.com/xap/1.0/sType/Font\c_hash_str}
\__pdfmeta_xmp_xmlns_new:nn {Iptc4xmpCore}{http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/}
\__pdfmeta_xmp_xmlns_new:nn {pdfaExtension}{http://www.aiim.org/pdfa/ns/extension/}
\__pdfmeta_xmp_xmlns_new:ne {pdfaSchema}{http://www.aiim.org/pdfa/ns/schema\c_hash_str}
\__pdfmeta_xmp_xmlns_new:ne {pdfaProperty}{http://www.aiim.org/pdfa/ns/property\c_hash_str}
\__pdfmeta_xmp_xmlns_new:ne {pdfaType} {http://www.aiim.org/pdfa/ns/type\c_hash_str}
\__pdfmeta_xmp_xmlns_new:ne {pdfaField}{http://www.aiim.org/pdfa/ns/field\c_hash_str}

\seq_new:N \l__pdfmeta_xmp_schema_seq
\cs_new_protected:Npn \__pdfmeta_xmp_schema_new:nnn #1 #2 #3
  %#1 name #2 prefix, #3 text
  {
    \seq_put_right:Nn \l__pdfmeta_xmp_schema_seq { #2 }
    \tl_new:c { g__pdfmeta_xmp_schema_#2_tl }
    \tl_new:c { g__pdfmeta_xmp_schema_#2_properties_tl }
    \tl_gput_right:cn { g__pdfmeta_xmp_schema_#2_tl }
      {
        \__pdfmeta_xmp_add_packet_open_attr:nnn{rdf}{li}{rdf:parseType="Resource"}
         \__pdfmeta_xmp_add_packet_line:nnn {pdfaSchema}{schema}{#1}
         \__pdfmeta_xmp_add_packet_line:nnn {pdfaSchema}{prefix}{#2}
         \__pdfmeta_xmp_add_packet_line:nnn {pdfaSchema}{namespaceURI}{#3}
         \__pdfmeta_xmp_add_packet_open:nn {pdfaSchema}{property}
          \__pdfmeta_xmp_add_packet_open:nn{rdf}{Seq}
              \tl_use:c { g__pdfmeta_xmp_schema_#2_properties_tl }
          \__pdfmeta_xmp_add_packet_close:nn{rdf}{Seq}
         \__pdfmeta_xmp_add_packet_close:nn {pdfaSchema}{property}
        \cs_if_exist_use:c {__pdfmeta_xmp_schema_#2_additions:}
        \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
      }
  }

\cs_new_protected:Npn \__pdfmeta_xmp_property_new:nnnnn #1 #2 #3 #4 #5 %
    %#1 schema #2 name, #3 type, #4 category #5 description
  {
    \tl_gput_right:cn { g__pdfmeta_xmp_schema_#1_properties_tl }
      {
        \__pdfmeta_xmp_add_packet_open:nn {rdf}{li~rdf:parseType="Resource"}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaProperty}{name}{#2}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaProperty}{valueType}{#3}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaProperty}{category}{#4}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaProperty}{description}{#5}
        \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
     }
  }

\cs_new_protected:Npn \__pdfmeta_xmp_add_packet_field:nnn #1 #2 #3 %
  %#1 name #2 valuetype #3 description
  {
    \__pdfmeta_xmp_add_packet_open_attr:nnn {rdf}{li}{rdf:parseType="Resource"}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaField}{name}{#1}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaField}{valueType}{#2}
          \__pdfmeta_xmp_add_packet_line:nnn {pdfaField}{description}{#3}
    \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
  }
\__pdfmeta_xmp_schema_new:nnn
   {XMP~Media~Management~Schema}
   {xmpMM}
   {http://ns.adobe.com/xap/1.0/mm/}
\__pdfmeta_xmp_property_new:nnnnn
   {xmpMM}
   {OriginalDocumentID}
   {URI}
   {internal}
   {The~common~identifier~for~all~versions~and~renditions~of~a~document.}
\__pdfmeta_xmp_schema_new:nnn
   {PDF/A~Identification~Schema}
   {pdfaid}
   {http://www.aiim.org/pdfa/ns/id/}
\__pdfmeta_xmp_property_new:nnnnn
   {pdfaid}
   {year}
   {Integer}
   {internal}
   {Year~of~standard}
\__pdfmeta_xmp_schema_new:nnn
   {PDF/UA~Universal~Accessibility~Schema}
   {pdfuaid}
   {http://www.aiim.org/pdfua/ns/id/}
\__pdfmeta_xmp_property_new:nnnnn
   {pdfuaid}
   {part}
   {Integer}
   {internal}
   {Part~of~ISO~14289~standard}
\__pdfmeta_xmp_property_new:nnnnn
   {pdfuaid}
   {rev}
   {Integer}
   {internal}
   {Revision~of~ISO~14289~standard}
\__pdfmeta_xmp_schema_new:nnn
    {PDF/X~ID~Schema}
    {pdfxid}
    {http://www.npes.org/pdfx/ns/id/}
\__pdfmeta_xmp_property_new:nnnnn
    {pdfxid}
    {GTS_PDFXVersion}
    {Text}
    {internal}
    {ID~of~PDF/X~standard}

\__pdfmeta_xmp_schema_new:nnn
  {PRISM~Basic~Metadata}
  {prism}
  {http://prismstandard.org/namespaces/basic/3.0/}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {complianceProfile}
  {Text}
  {internal}
  {PRISM~specification~compliance~profile~to~which~this~document~adheres}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {publicationName}
  {Text}
  {external}
  {Publication~name}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {aggregationType}
  {Text}
  {external}
  {Publication~type}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {bookEdition}
  {Text}
  {external}
  {Edition~of~the~book~in~which~the~document~was~published}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {volume}
  {Text}
  {external}
  {Publication~volume~number}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {number}
  {Text}
  {external}
  {Publication~issue~number~within~a~volume}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {pageRange}
  {Text}
  {external}
  {Page~range~for~the~document~within~the~print~version~of~its~publication}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {issn}
  {Text}
  {external}
  {ISSN~for~the~printed~publication~in~which~the~document~was~published}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {eIssn}
  {Text}
  {external}
  {ISSN~for~the~electronic~publication~in~which~the~document~was~published}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {isbn}
  {Text}
  {external}
  {ISBN~for~the~publication~in~which~the~document~was~published}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {doi}
  {Text}
  {external}
  {Digital~Object~Identifier~for~the~document}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {url}
  {URL}
  {external}
  {URL~at~which~the~document~can~be~found}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {byteCount}
  {Integer}
  {internal}
  {Approximate~file~size~in~octets}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {pageCount}
  {Integer}
  {internal}
  {Number~of~pages~in~the~print~version~of~the~document}
\__pdfmeta_xmp_property_new:nnnnn
  {prism}
  {subtitle}
  {Text}
  {external}
  {Document's~subtitle}
\__pdfmeta_xmp_schema_new:nnn
  {IPTC~Core~Schema}
  {Iptc4xmpCore}
  {http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/}
\__pdfmeta_xmp_property_new:nnnnn
  {Iptc4xmpCore}
  {CreatorContactInfo}
  {ContactInfo}
  {external}
  {Document~creator's~contact~information}
\cs_new_protected:cpn { __pdfmeta_xmp_schema_Iptc4xmpCore_additions: }
  {
    \__pdfmeta_xmp_add_packet_open:nn{pdfaSchema}{valueType}
      \__pdfmeta_xmp_add_packet_open:nn{rdf}{Seq}
        \__pdfmeta_xmp_add_packet_open_attr:nnn{rdf}{li}{rdf:parseType="Resource"}
          \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{type}{ContactInfo}
          \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{namespaceURI}
             {http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/}
          \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{prefix}{Iptc4xmpCore}
          \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{description}
            {Basic~set~of~information~to~get~in~contact~with~a~person}
          \__pdfmeta_xmp_add_packet_open:nn{pdfaType}{field}
           \__pdfmeta_xmp_add_packet_open:nn{rdf}{Seq}
            \__pdfmeta_xmp_add_packet_field:nnn{CiAdrCity}{Text}
              {Contact~information~city}
            \__pdfmeta_xmp_add_packet_field:nnn{CiAdrCtry}{Text}
              {Contact~information~country}
            \__pdfmeta_xmp_add_packet_field:nnn{CiAdrExtadr}{Text}
              {Contact~information~address}
            \__pdfmeta_xmp_add_packet_field:nnn{CiAdrPcode}{Text}
              {Contact~information~local~postal~code}
            \__pdfmeta_xmp_add_packet_field:nnn{CiAdrRegion}{Text}
              {Contact~information~regional~information~such~as~state~or~province}
            \__pdfmeta_xmp_add_packet_field:nnn{CiEmailWork}{Text}
              {Contact~information~email~address(es)}
            \__pdfmeta_xmp_add_packet_field:nnn{CiTelWork}{Text}
              {Contact~information~telephone~number(s)}
            \__pdfmeta_xmp_add_packet_field:nnn{CiUrlWork}{Text}
              {Contact~information~Web~URL(s)}
           \__pdfmeta_xmp_add_packet_close:nn{rdf}{Seq}
         \__pdfmeta_xmp_add_packet_close:nn{pdfaType}{field}
        \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
      \__pdfmeta_xmp_add_packet_close:nn{rdf}{Seq}
    \__pdfmeta_xmp_add_packet_close:nn{pdfaSchema}{valueType}
  }
\cs_new_protected:Npn \__pdfmeta_xmp_schema_enable_pdfd:
 {
  \__pdfmeta_xmp_xmlns_new:ne {pdfd}{http://pdfa.org/declarations/}
  \__pdfmeta_xmp_schema_new:nnn
    {PDF~Declarations~Schema}
    {pdfd}
    {http://pdfa.org/declarations/}
  \__pdfmeta_xmp_property_new:nnnnn
    {pdfd}
    {declarations}
    {Bag~declaration}
    {external}
    {An~unordered~array~of~PDF~Declaration~entries,~where~each~PDF~Declaration~representing~a~statement~of~conformance~with~ an~identified~external~standard~or~profile,~along~with~optional~information~identifying~the~nature~of~the~claim.}
  \cs_new_protected:cpn { __pdfmeta_xmp_schema_pdfd_additions: }
    {
      \__pdfmeta_xmp_add_packet_open:nn{pdfaSchema}{valueType}
        \__pdfmeta_xmp_add_packet_open:nn{rdf}{Seq}
          \__pdfmeta_xmp_add_packet_open_attr:nnn{rdf}{li}{rdf:parseType="Resource"}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{type}{claim}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{namespaceURI}
               {http://pdfa.org/declarations/}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{prefix}{pdfd}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{description}
              {A~structure~describing~properties~of~an~individual claim.}
            \__pdfmeta_xmp_add_packet_open:nn{pdfaType}{field}
             \__pdfmeta_xmp_add_packet_open:nn{rdf}{Seq}
              \__pdfmeta_xmp_add_packet_field:nnn{claimReport}{Text}
                {A~URL~to~a~report~containing~details~of~the~specific~conformance~claim.}
              \__pdfmeta_xmp_add_packet_field:nnn{claimCredentials}{Text}
                {The~claimant's~credentials.}
              \__pdfmeta_xmp_add_packet_field:nnn{claimDate}{Text}
                {A~date~identifying~when~the~claim~was~made.}
              \__pdfmeta_xmp_add_packet_field:nnn{claimBy}{Text}
                {The~name~of~the~organization~and/or~individual~and/or~software~making~the~claim.}
             \__pdfmeta_xmp_add_packet_close:nn{rdf}{Seq}
           \__pdfmeta_xmp_add_packet_close:nn{pdfaType}{field}
          \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
          \__pdfmeta_xmp_add_packet_open_attr:nnn{rdf}{li}{rdf:parseType="Resource"}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{type}{declaration}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{namespaceURI}
               {http://pdfa.org/declarations/}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{prefix}{pdfd}
            \__pdfmeta_xmp_add_packet_line:nnn{pdfaType}{description}
              {A~structure~describing~a~single~PDF~ Declaration~asserting~conformance~with~ an~externally-identified~standard~or~ profile.}
            \__pdfmeta_xmp_add_packet_open:nn{pdfaType}{field}
             \__pdfmeta_xmp_add_packet_open:nn{rdf}{Seq}
              \__pdfmeta_xmp_add_packet_field:nnn{conformsTo}{Text}
                {A~property~containing~a~URI~specifying~the~standard~or~profile~by~the~PDF~Declaration.~This~property~is~ intended~to~mirror~the~Dublin~Core~property~dc:conformsTo.}
              \__pdfmeta_xmp_add_packet_field:nnn{claimData}{Bag~claim}
                {An~unordered~array~of~claim~data,~where~each~claim~identifies~the~nature~of~the~claim.}
             \__pdfmeta_xmp_add_packet_close:nn{rdf}{Seq}
           \__pdfmeta_xmp_add_packet_close:nn{pdfaType}{field}
          \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
        \__pdfmeta_xmp_add_packet_close:nn{rdf}{Seq}
      \__pdfmeta_xmp_add_packet_close:nn{pdfaSchema}{valueType}
    }
   \cs_gset_eq:NN \__pdfmeta_xmp_schema_enable_pdfd: \prg_do_nothing:
 }

\cs_new_protected:Npn \__pdfmeta_xmp_build_pdf:
  {
  \__pdfmeta_xmp_add_packet_line_default:nnee
    {pdf}{Producer}
    {\c_sys_engine_exec_str-\c_sys_engine_version_str}
    {\GetDocumentProperties{hyperref/pdfproducer}}
   \__pdfmeta_xmp_add_packet_line:nne{pdf}{PDFVersion}{\pdf_version:}
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_xmp:
  {
  \__pdfmeta_xmp_add_packet_line_default:nnee
    {xmp}{CreatorTool}
    {LaTeX}
    { \GetDocumentProperties{hyperref/pdfcreator} }
   \__pdfmeta_xmp_add_packet_line_default:nnee
     {xmp}{BaseURL}{}
     { \GetDocumentProperties{hyperref/baseurl} }
    \__pdfmeta_xmp_date_get:nNN
      {document/creationdate}\l__pdfmeta_tmpa_tl\l__pdfmeta_tmpa_seq
    \__pdfmeta_xmp_add_packet_line:nne{xmp}{CreateDate}{\__pdfmeta_xmp_print_date:N\l__pdfmeta_tmpa_seq}
    \pdfmanagement_add:nne{Info}{CreationDate}{(\l__pdfmeta_tmpa_tl)}
    \__pdfmeta_xmp_date_get:nNN
      {document/moddate}\l__pdfmeta_tmpa_tl\l__pdfmeta_tmpa_seq
    \__pdfmeta_xmp_add_packet_line:nne{xmp}{ModifyDate}{\__pdfmeta_xmp_print_date:N\l__pdfmeta_tmpa_seq}
    \pdfmanagement_add:nne{Info}{ModDate}{(\l__pdfmeta_tmpa_tl)}
    \__pdfmeta_xmp_date_get:nNN
      {hyperref/pdfmetadate}\l__pdfmeta_tmpa_tl\l__pdfmeta_tmpa_seq
    \__pdfmeta_xmp_add_packet_line:nne{xmp}{MetadataDate}{\__pdfmeta_xmp_print_date:N\l__pdfmeta_tmpa_seq}
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_standards:
  {
    \__pdfmeta_xmp_add_packet_line:nne {pdfaid}{part}{\pdfmeta_standard_item:n{level}}
    \__pdfmeta_xmp_add_packet_line:nne
      {pdfaid}{conformance}{\pdfmeta_standard_item:n{conformance}}
    \int_compare:nNnTF {0\pdfmeta_standard_item:n{level}}<{4}
     {\__pdfmeta_xmp_add_packet_line:nne {pdfaid}{year} {\pdfmeta_standard_item:n{year}}}
     {\__pdfmeta_xmp_add_packet_line:nne {pdfaid}{rev}  {\pdfmeta_standard_item:n{year}}}
    \__pdfmeta_xmp_add_packet_line:nne
      {pdfxid}{GTS_PDFXVersion}{\GetDocumentProperties{document/pdfstandard-X}}
    \pdfmanagement_get_documentproperties:nNT {document/pdfstandard-UA}\l__pdfmeta_tmpa_tl
     {
       \__pdfmeta_xmp_add_packet_line:nne
        {pdfuaid}{part}{\exp_last_unbraced:No\use_i:nn \l__pdfmeta_tmpa_tl}
      \__pdfmeta_xmp_add_packet_line:nne
        {pdfuaid}{rev}{\exp_last_unbraced:No\use_ii:nn \l__pdfmeta_tmpa_tl}
     }
  }
\prop_new:N \g__pdfmeta_xmp_pdfd_data_prop
\cs_new_protected:Npn \__pdfmeta_xmp_build_pdfd:
  {
    \prop_if_empty:NF\g__pdfmeta_xmp_pdfd_data_prop
      {
        \__pdfmeta_xmp_add_packet_open:nn{pdfd}{declarations}
        \__pdfmeta_xmp_add_packet_open:nn{rdf}{Bag}
          \prop_map_inline:Nn \g__pdfmeta_xmp_pdfd_data_prop
            {
              \__pdfmeta_xmp_build_pdfd_claim:nn{##1}{##2}
            }
        \__pdfmeta_xmp_add_packet_close:nn{rdf}{Bag}
        \__pdfmeta_xmp_add_packet_close:nn{pdfd}{declarations}
      }
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_pdfd_claim:nn #1#2
 {
    \__pdfmeta_xmp_add_packet_open_attr:nnn{rdf}{li}{rdf:parseType="Resource"}
      \__pdfmeta_xmp_add_packet_line:nnn{pdfd}{conformsTo}{#1}
      \tl_if_empty:nF {#2}
       {
         \__pdfmeta_xmp_add_packet_open:nn{pdfd}{claimData}
          \__pdfmeta_xmp_add_packet_open:nn{rdf}{Bag}
            #2
          \__pdfmeta_xmp_add_packet_close:nn{rdf}{Bag}
         \__pdfmeta_xmp_add_packet_close:nn{pdfd}{claimData}
       }
    \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
 }
\cs_new_protected:Npn \__pdfmeta_xmp_build_photoshop:
  {
   \__pdfmeta_xmp_add_packet_line:nne{photoshop}{AuthorsPosition}
     { \GetDocumentProperties{hyperref/pdfauthortitle} }
   \__pdfmeta_xmp_add_packet_line:nne{photoshop}{CaptionWriter}
     { \GetDocumentProperties{hyperref/pdfcaptionwriter} }
  }


\cs_new_protected:Npn \__pdfmeta_xmp_build_xmpMM:
  {
    \str_set:Ne\l__pdfmeta_tmpa_str {\GetDocumentProperties{hyperref/pdfdocumentid}}
    \str_if_empty:NT \l__pdfmeta_tmpa_str
      {
        \__pdfmeta_xmp_create_uuid:nN
          {\jobname\GetDocumentProperties{hyperref/pdftitle}}
          \l__pdfmeta_tmpa_str
      }
    \__pdfmeta_xmp_add_packet_line:nnV{xmpMM}{DocumentID}
      \l__pdfmeta_tmpa_str
    \str_set:Ne\l__pdfmeta_tmpa_str {\GetDocumentProperties{hyperref/pdfinstanceid}}
    \str_if_empty:NT \l__pdfmeta_tmpa_str
      {
        \__pdfmeta_xmp_create_uuid:nN
          {\jobname\l__pdfmeta_xmp_currentdate_tl}
          \l__pdfmeta_tmpa_str
      }
    \__pdfmeta_xmp_add_packet_line:nnV{xmpMM}{InstanceID}
      \l__pdfmeta_tmpa_str
   \__pdfmeta_xmp_add_packet_line:nne{xmpMM}{VersionID}
     { \GetDocumentProperties{hyperref/pdfversionid} }
   \__pdfmeta_xmp_add_packet_line:nne{xmpMM}{RenditionClass}
     { \GetDocumentProperties{hyperref/pdfrendition} }
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_dc:
  {
    \__pdfmeta_xmp_add_packet_list:nnne {dc}{creator}{Seq}
       { \GetDocumentProperties{hyperref/pdfauthor} }
    \int_compare:nNnT {0\pdfmeta_standard_item:n{level}}={1}
       { \pdfmanagement_remove:nn{Info}{Author} }
    \__pdfmeta_xmp_add_packet_list:nnne {dc}{title}{Alt}
       { \GetDocumentProperties{hyperref/pdftitle} }
    \__pdfmeta_xmp_add_packet_list:nnne {dc}{subject}{Bag}
       { \GetDocumentProperties{hyperref/pdfkeywords} }
    \int_compare:nNnT {0\pdfmeta_standard_item:n{level}}={1}
       { \pdfmanagement_remove:nn{Info}{Keywords} }
  \pdfmanagement_get_documentproperties:nNTF { hyperref/pdftype } \l__pdfmeta_tmpa_tl
    {
      \__pdfmeta_xmp_add_packet_list_simple:nnnV {dc}{type}{Bag}\l__pdfmeta_tmpa_tl
    }
    {
      \__pdfmeta_xmp_add_packet_list_simple:nnnn {dc}{type}{Bag}{Text}
    }
   \__pdfmeta_xmp_add_packet_list:nnne {dc}{publisher}{Bag}
     { \GetDocumentProperties{hyperref/pdfpublisher} }
   \__pdfmeta_xmp_add_packet_list:nnne
    {dc}{description}{Alt}
    {\GetDocumentProperties{hyperref/pdfsubject}}
   \__pdfmeta_xmp_add_packet_list_simple:nnnV
     {dc}{language}{Bag}\l__pdfmeta_xmp_doclang_tl
   \__pdfmeta_xmp_add_packet_line:nne{dc}{identifier}
     { \GetDocumentProperties{hyperref/pdfidentifier} }
   \__pdfmeta_xmp_date_get:nNN {hyperref/pdfdate}\l__pdfmeta_tmpa_tl\l__pdfmeta_tmpa_seq
    \__pdfmeta_xmp_add_packet_list_simple:nnne
     {dc}{date}{Seq}{\__pdfmeta_xmp_print_date:N\l__pdfmeta_tmpa_seq}
   \__pdfmeta_xmp_add_packet_line:nnn{dc}{format}{application/pdf}
    \__pdfmeta_xmp_add_packet_line_default:nnee
     {dc}{source}
     { \c_sys_jobname_str.tex }
     { \GetDocumentProperties{hyperref/pdfsource} }
    \__pdfmeta_xmp_add_packet_list:nnne{dc}{rights}{Alt}
     {\GetDocumentProperties{hyperref/pdfcopyright}}
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_xmpRights:
  {
    \__pdfmeta_xmp_add_packet_line:nne
      {xmpRights}
      {WebStatement}
      {\GetDocumentProperties{hyperref/pdflicenseurl}}
    \__pdfmeta_xmp_add_packet_line:nne
      {xmpRights}
      {Marked}
      {
       \str_case:en {\GetDocumentProperties{document/copyright}}
        {
          {true}{True}
          {false}{False}
        }
      }
  }
\tl_new:N\l__pdfmeta_xmp_iptc_data_tl
\cs_new_protected:Npn \__pdfmeta_xmp_build_iptc_data:N #1
  {
     \tl_clear:N #1
     \__pdfmeta_xmp_incr_indent:\__pdfmeta_xmp_incr_indent:\__pdfmeta_xmp_incr_indent:\__pdfmeta_xmp_incr_indent:
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiAdrExtadr}
       {\GetDocumentProperties{hyperref/pdfcontactaddress}}
       #1
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiAdrCity}
       {\GetDocumentProperties{hyperref/pdfcontactcity}}
       #1
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiAdrPcode}
       {\GetDocumentProperties{hyperref/pdfcontactpostcode}}
       #1
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiAdrCtry}
       {\GetDocumentProperties{hyperref/pdfcontactcountry}}
       #1
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiTelWork}
       {\GetDocumentProperties{hyperref/pdfcontactphone}}
       #1
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiEmailWork}
       {\GetDocumentProperties{hyperref/pdfcontactemail}}
       #1
     \__pdfmeta_xmp_add_packet_line:nneN
       {Iptc4xmpCore}{CiUrlWork}
       {\GetDocumentProperties{hyperref/pdfcontacturl}}
       #1
     \__pdfmeta_xmp_decr_indent:\__pdfmeta_xmp_decr_indent:\__pdfmeta_xmp_decr_indent:\__pdfmeta_xmp_decr_indent:
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_iptc:
  {
    \tl_if_empty:NF\l__pdfmeta_xmp_iptc_data_tl
     {
       \__pdfmeta_xmp_add_packet_open_attr:nnn
        {Iptc4xmpCore}{CreatorContactInfo}{rdf:parseType="Resource"}
       \tl_gput_right:Ne\g__pdfmeta_xmp_packet_tl { \l__pdfmeta_xmp_iptc_data_tl }
       \__pdfmeta_xmp_add_packet_close:nn
        {Iptc4xmpCore}{CreatorContactInfo}
    }
  }
\cs_new_protected:Npn \__pdfmeta_xmp_build_prism:
  {
    \__pdfmeta_xmp_add_packet_line:nnn
      {prism}{complianceProfile}
      {three}
    \__pdfmeta_xmp_lang_get:eNN
     {\GetDocumentProperties{hyperref/pdfsubtitle}}
     \l__pdfmeta_tmpa_tl\l__pdfmeta_tmpb_tl
    \__pdfmeta_xmp_add_packet_line_attr:nneV
      {prism}{subtitle}
      {xml:lang="\l__pdfmeta_tmpa_tl"}
      \l__pdfmeta_tmpb_tl
    \__pdfmeta_xmp_lang_get:eNN
     {\GetDocumentProperties{hyperref/pdfpublication}}
     \l__pdfmeta_tmpa_tl\l__pdfmeta_tmpb_tl
    \__pdfmeta_xmp_add_packet_line_attr:nneV
      {prism}{publicationName}
      {xml:lang="\l__pdfmeta_tmpa_tl"}
      \l__pdfmeta_tmpb_tl
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{bookEdition}
      {\GetDocumentProperties{hyperref/pdfbookedition}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{aggregationType}
      {\GetDocumentProperties{hyperref/pdfpubtype}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{volume}
      {\GetDocumentProperties{hyperref/pdfvolumenum}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{number}
      {\GetDocumentProperties{hyperref/pdfissuenum}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{pageRange}
      {\GetDocumentProperties{hyperref/pdfpagerange}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{issn}
      {\GetDocumentProperties{hyperref/pdfissn}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{eIssn}
      {\GetDocumentProperties{hyperref/pdfeissn}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{doi}
      {\GetDocumentProperties{hyperref/pdfdoi}}
    \__pdfmeta_xmp_add_packet_line:nne
      {prism}{url}
      {\GetDocumentProperties{hyperref/pdfurl}}
     \tl_set:Ne \l__pdfmeta_tmpa_tl { \GetDocumentProperties{hyperref/pdfnumpages} }
     \__pdfmeta_xmp_add_packet_line:nne
      {prism}{pageCount}
      {\tl_if_blank:VTF \l__pdfmeta_tmpa_tl {\PreviousTotalPages}{\l__pdfmeta_tmpa_tl}}
  }
\tl_new:N \g__pdfmeta_xmp_user_packet_tl
\cs_new_protected:Npn \__pdfmeta_xmp_build_user:
 {
   \int_zero:N \l__pdfmeta_xmp_indent_int
   \g__pdfmeta_xmp_user_packet_tl
   \int_set:Nn \l__pdfmeta_xmp_indent_int {3}
 }
\AddToHook{shipout/lastpage}
  {
    \bool_if:NT\g__pdfmeta_xmp_bool
     {
       \str_if_exist:NTF\c_sys_timestamp_str
        {
          \tl_set_eq:NN \l__pdfmeta_xmp_currentdate_tl \c_sys_timestamp_str
        }
        {
          \file_get_timestamp:nN{\jobname.log}\l__pdfmeta_xmp_currentdate_tl
        }
       \__pdfmeta_xmp_date_split:VN\l__pdfmeta_xmp_currentdate_tl\l__pdfmeta_xmp_currentdate_seq
       \__pdfmeta_xmp_build_packet:
       \exp_args:No
       \__pdf_backend_metadata_stream:n {\g__pdfmeta_xmp_packet_tl}
        \pdfmanagement_add:nne {Catalog} {Metadata}{\pdf_object_ref_last:}
       \bool_if:NT \g__pdfmeta_xmp_export_bool
        {
          \iow_open:Nn\g_tmpa_iow{\g__pdfmeta_xmp_export_str.xmpi}
          \exp_args:NNo\iow_now:Nn\g_tmpa_iow{\g__pdfmeta_xmp_packet_tl}
          \iow_close:N\g_tmpa_iow
        }
     }
  }


\cs_new_protected:Npn \pdfmeta_xmp_add:n #1
  {
    \tl_gput_right:Nn \g__pdfmeta_xmp_user_packet_tl
      {
        \__pdfmeta_xmp_add_packet_chunk:n { #1 }
      }
  }
\cs_new_protected:Npn \pdfmeta_xmp_xmlns_new:nn #1 #2
  {
    \prop_if_in:NnTF \g__pdfmeta_xmp_xmlns_prop {#1}
      {\msg_warning:nnn{pdfmeta}{namespace-defined}{#1}}
      {\__pdfmeta_xmp_xmlns_new:nn {#1}{#2}}
  }
\cs_new_protected:Npn \pdfmeta_xmp_add_declaration:n #1 %conformsTo uri
 {
   \__pdfmeta_xmp_schema_enable_pdfd:
   \prop_gput:Nnn\g__pdfmeta_xmp_pdfd_data_prop{#1}{}
 }
\cs_generate_variant:Nn \pdfmeta_xmp_add_declaration:n {e}
\cs_new_protected:Npn \pdfmeta_xmp_add_declaration:nnnnn #1#2#3#4#5
 %#1=conformsTo uri, #2 claimBy, #3 claimDate #4 claimCredentials #4 claimReport
 {
   \__pdfmeta_xmp_schema_enable_pdfd:
   \tl_set:Nn \l__pdfmeta_tmpa_tl
     {
       \__pdfmeta_xmp_add_packet_open_attr:nnn{rdf}{li}{rdf:parseType="Resource"}
       \__pdfmeta_xmp_add_packet_line:nnn{pdfd}{claimBy}{#2}
       \__pdfmeta_xmp_add_packet_line:nnn{pdfd}{claimDate}{#3}
       \__pdfmeta_xmp_add_packet_line:nnn{pdfd}{claimCredentials}{#4}
       \__pdfmeta_xmp_add_packet_line:nnn{pdfd}{claimReport}{#5}
       \__pdfmeta_xmp_add_packet_close:nn{rdf}{li}
     }
   \prop_get:NnNT \g__pdfmeta_xmp_pdfd_data_prop {#1}\l__pdfmeta_tmpb_tl
    {
      \tl_concat:NNN \l__pdfmeta_tmpa_tl \l__pdfmeta_tmpa_tl \l__pdfmeta_tmpb_tl
    }
   \prop_gput:Nno\g__pdfmeta_xmp_pdfd_data_prop{#1}
       {
         \l__pdfmeta_tmpa_tl
       }
 }
\cs_generate_variant:Nn\pdfmeta_xmp_add_declaration:nnnnn {e,eee}

\cs_new:Npn \__pdfmeta_xmp_iso_today:
  {
    \int_use:N\c_sys_year_int-
    \int_compare:nNnT {\c_sys_month_int} < {10}{0} \int_use:N\c_sys_month_int -
    \int_compare:nNnT {\c_sys_day_int}   < {10}{0} \int_use:N\c_sys_day_int
  }
\cs_new_protected:Npn \__pdfmeta_xmp_wtpdf_reuse_declaration:
 {
   \pdfmeta_xmp_add_declaration:eeenn
      {http://pdfa.org/declarations\c_hash_str wtpdf-reuse1.0}
      {LaTeX~Project}
      {\__pdfmeta_xmp_iso_today:}{}{}
 }
\cs_new_protected:Npn \__pdfmeta_xmp_wtpdf_accessibility_declaration:
 {
   \pdfmeta_xmp_add_declaration:ennnn
     {http://pdfa.org/declarations\c_hash_str wtpdf-accessibility1.0}
     {LaTeX~Project}
     {\__pdfmeta_xmp_iso_today:}{}{}
 }
%% File: l3pdftools.dtx
\cs_generate_variant:Nn \str_convert_pdfname:n { e }

\cs_new:Npn \pdf_name_from_unicode_e:n #1
  {
    \__kernel_pdf_name_from_unicode_e:n { #1 }
  }

\cs_generate_variant:Nn \pdf_name_from_unicode_e:n {V}
\bool_lazy_any:nTF
  {
    \sys_if_engine_luatex_p:
    \sys_if_engine_xetex_p:
  }
  {
    \prop_gput:Nnn \g__str_alias_prop { default } {  }
  }
  {
    \prop_gput:Nnn \g__str_alias_prop { default } { utf8 }
  }
\msg_new:nnn {pdfmanagement}{ unknown-convert}
 {
   Unknown~string~conversion~method~'#1'!
 }
\cs_new:Npn \pdf_string_from_unicode:nnN #1 #2 #3
  {
    \cs_if_exist_use:cF { __pdf_string_from_unicode_#1:nN }
      {
        \msg_error:nnn { pdf } { unknown-convert } {#1}
        \use_none:nn
      }
    { #2 } #3
  }

\cs_generate_variant:Nn \pdf_string_from_unicode:nnN {nVN}
%% TODO Names need a review when it is clear which converters
%% are actually needed
%% string conversions and printing
%% we assume here that the text purify step has been done. The input is
%% a list of (utf8) chars.
%% str convert, not expandable.


\cs_new_protected:cpn { __pdf_string_from_unicode_utf8/string-raw:nN }  #1 #2
  {
     \str_set_convert:Nnnn #2
        { #1 }
        { default }
        {utf8/string}
  }

\cs_new_protected:cpn { __pdf_string_from_unicode_utf8/string:nN } #1 #2
  {
    \use:c { __pdf_string_from_unicode_utf8/string-raw:nN } { #1 } #2
    \str_put_left:Nn #2  {(}
    \str_put_right:Nn #2 {)}
  }
\cs_new_protected:cpx { __pdf_string_from_unicode_utf8/URI-raw:nN }  #1 #2
  {
     \exp_not:N \str_set_convert:Nnnn #2
       { #1 }
       { default }
       {utf8/url}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3A} {:}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2F} {/}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 23} {\c_hash_str}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 5B} {[}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 5D} {]}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 40} {\c_atsign_str}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 21} {!}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 24} {\c_dollar_str}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 26} {\c_ampersand_str}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 27} {'}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2A} {*}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2B} {+}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 2C} {,}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3B} {;}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3D} {=}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 3F} {?}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 30} {0}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 31} {1}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 32} {2}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 33} {3}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 34} {4}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 35} {5}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 36} {6}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 37} {7}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 38} {8}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 39} {9}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 28} {\c_backslash_str(}
     \exp_not:N \str_replace_all:Nnn #2 {\c_percent_str 29} {\c_backslash_str)}
  }

\cs_new_protected:cpn { __pdf_string_from_unicode_utf8/URI:nN } #1 #2
  {
     \use:c { __pdf_string_from_unicode_utf8/URI-raw:nN } {#1} #2
     \str_put_left:Nn #2  {(}
     \str_put_right:Nn #2 {)}
  }
\cs_new_protected:cpn { __pdf_string_from_unicode_utf16/string-raw:nN }  #1 #2
  {
    \str_set_convert:Nnnn #2
      { #1 }
      { default }
      {utf16/string}
  }

\cs_new_protected:cpn { __pdf_string_from_unicode_utf16/string:nN } #1 #2
  {
    \use:c { __pdf_string_from_unicode_utf16/string-raw:nN } {#1} #2
    \str_put_left:Nn #2  {(}
    \str_put_right:Nn #2 {)}
  }

\cs_new_protected:cpn { __pdf_string_from_unicode_utf16/hex-raw:nN } #1 #2
  {
     \str_set_convert:Nnnn #2
       { #1 }
       { default }
       {utf16/hex}
  }

\cs_new_protected:cpn { __pdf_string_from_unicode_utf16/hex:nN } #1 #2
  {
    \use:c { __pdf_string_from_unicode_utf16/hex-raw:nN } {#1} #2
    \str_put_left:Nn #2  {<}
    \str_put_right:Nn #2 {>}
  }

\cs_new_protected:Npn  \pdf_bdc:nn #1 #2 { \__pdf_backend_bdc:nn { #1 }{ #2 } }
\cs_generate_variant:Nn \pdf_bdc:nn {ee}

\cs_new_protected:Npn  \pdf_bdc_shipout:ee #1 #2
  {
    \bool_if:NTF\l__pdfmanagement_delayed_shipout_bool
      {
        \__pdf_backend_bdc_shipout:ee { #1 }{ #2 }
        \cs_gset_eq:NN \pdf_bdc_shipout:ee \__pdf_backend_bdc_shipout:ee
      }
      {
        \msg_error:nn {pdfmanagement}{delayed-shipout}
        \cs_gset_eq:NN \pdf_bdc_shipout:ee  \use_none:nn
      }
  }
\cs_new_protected:Npn  \pdf_bdcobject:nn #1 #2 { \__pdf_backend_bdcobject:nn { #1 }{ #2 } }
\cs_new_protected:Npn  \pdf_bdcobject:n #1     { \__pdf_backend_bdcobject:n  { #1 } }
\cs_new_protected:Npn  \pdf_bmc:n #1     { \__pdf_backend_bmc:n  { #1 } }
\cs_new_protected:Npn  \pdf_emc:         { \__pdf_backend_emc: }
%% File: l3pdffile.dtx

\cs_new_protected:Npn \__pdffile_filename_convert_to_print:nN #1 #2
  {\pdf_string_from_unicode:nnN {utf16/hex}{#1}{#2}}
\msg_new:nnn { pdffile } { file-not-found }
  {
    File~'\tl_to_str:n{#1}'~not~found
  }

\msg_new:nnn { pdffile } { mimetype-missing }
  {
    Mime~type~not~set~for~file~'\tl_to_str:n{#1}'
  }

\msg_new:nnn { pdffile } { target-name-missing }
  {
    a~target~name~for~the~/Filespec~dictionary~is~missing.
  }

\msg_new:nnn { pdffile } { object-exists }
  {
    object~name~'#1'~is~already~used.
  }

\msg_new:nnn  { pdffile } { show-files }
  {
    The~following~files~have~been~embedded\\
     #1
  }
\tl_new:N  \l__pdffile_tmpa_tl
\tl_new:N  \l__pdffile_tmpb_tl
\tl_new:N  \g__pdffile_tmpa_tl
\str_new:N \l__pdffile_tmpa_str
\str_new:N \l__pdffile_tmpb_str
\str_new:N \l__pdffile_ext_str
\tl_new:N  \l__pdffile_automimetype_tl
\tl_new:N  \l__pdffile_embed_ref_tl
\prop_new:N \g_pdffile_mimetypes_prop
\prop_gset_from_keyval:Nn \g_pdffile_mimetypes_prop
  {
    ,.css = text/css
    ,.csv = text/csv
    ,.html= text/html
    ,.dtx = text/plain %or application/x-tex, not in iana.org list
    ,.eps = application/postscript
    ,.jpg = image/jpeg
    ,.mp4 = video/mp4
    ,.pdf = application/pdf
    ,.png = image/png
    ,.tex = application/x-tex %not in iana.org list but probably better
    ,.txt = text/plain
    ,.sty = text/plain
    ,.xml = application/xml
  }
\str_new:N  \l_pdffile_source_name_str
\pdfdict_new:n { l_pdffile }
\pdfdict_put:nnn { l_pdffile }{Type}{/EmbeddedFile}
\pdfdict_new:n { l_pdffile/Params }
\pdfdict_put:nnn { l_pdffile/Params }
  {ModDate}  { (\file_timestamp:n { \l_pdffile_source_name_str }) }
\pdfdict_put:nnn { l_pdffile/Params }
  {Size}     { \file_size:n { \l_pdffile_source_name_str } }
\pdfdict_put:nnn { l_pdffile/Params }
  {CheckSum} { (\file_mdfive_hash:n { \l_pdffile_source_name_str }) }
\pdfdict_new:n { l_pdffile/streamParams }
\pdfdict_put:nnn { l_pdffile/streamParams }
  {ModDate}  {
               (
                 D:\int_use:N\c_sys_year_int
                  \int_compare:nNnT{\c_sys_month_int}<{10}{0}
                  \int_use:N\c_sys_month_int
                  \int_compare:nNnT{\c_sys_day_int}<{10}{0}
                  \int_use:N\c_sys_day_int
               )
             }
\pdfdict_new:n { l_pdffile/Filespec }
\pdfdict_put:nnn { l_pdffile/Filespec }
  {Type} { /Filespec }
\pdfdict_put:nnn { l_pdffile/Filespec }
  {AFRelationship} { /Unspecified }

\prop_new:N \g_pdffile_embed_prop
\cs_new_protected:Npn \pdffile_embed_show:
  {
    \msg_show:nne
     {pdffile}{show-files}
     {
       \prop_map_function:NN {\g_pdffile_embed_prop} \msg_show_item:nn
     }
  }
\cs_new_protected:Npn \__pdffile_mimetype_set:nN #1 #2
  {
    \file_parse_full_name:nNNN
          {#1}
          \l__pdffile_tmpa_str %unused
          \l__pdffile_tmpb_str %unused
          \l__pdffile_ext_str
        %check if Subtype has been set
        \pdfdict_get:nnN { l_pdffile}{Subtype}\l__pdffile_tmpa_tl
        %if not look up in the prop:
        \quark_if_no_value:NT \l__pdffile_tmpa_tl
          {
            \prop_get:NVNTF
              \g_pdffile_mimetypes_prop
              \l__pdffile_ext_str
              \l__pdffile_tmpb_tl
              {
                \tl_set:Ne #2 {/Subtype~\pdf_name_from_unicode_e:V \l__pdffile_tmpb_tl}
              }
              {
                \msg_warning:nne { pdffile }{ mimetype-missing} {#1}
                \tl_clear:N #2
              }
          }
    }

\cs_generate_variant:Nn \__pdffile_mimetype_set:nN {VN}

\cs_new_protected:Npn \__pdffile_fstream_write:nN #1 #2
  {
    \pdf_object_unnamed_write:ne { fstream }
      {
        {
          #2
          \pdfdict_use:n { l_pdffile}
          \pdfdict_if_empty:nF { l_pdffile/Params}
            {
              /Params
                <<
                  \pdfdict_use:n { l_pdffile/Params}
                >>
            }
        }
        { #1 }
      }
     \tl_clear:N \l__pdffile_automimetype_tl
   }

\cs_generate_variant:Nn \__pdffile_fstream_write:nN {VN}

\cs_new_protected:Npn \__pdffile_stream_write:nN #1 #2
  {
    \pdf_object_unnamed_write:ne { stream }
      {
        {
          #2
          \pdfdict_use:n { l_pdffile}
          \pdfdict_if_empty:nF { l_pdffile/streamParams}
            {
              /Params
                <<
                  \pdfdict_use:n { l_pdffile/streamParams}
                >>
            }
        }
        { \exp_not:n { #1 } }
      }
     \tl_clear:N \l__pdffile_automimetype_tl
   }

\cs_generate_variant:Nn \__pdffile_stream_write:nN {VN}

\cs_new_protected:Npn \__pdffile_filespec_write:nnn #1 #2 #3
  {
    \tl_if_blank:nTF { #2 }
      {
        \msg_error:nn {pdffile}{target-name-missing}
      }
      {
        \group_begin:
          \pdf_string_from_unicode:nnN {utf8/string}{#2}\l__pdffile_tmpa_str
          \pdfdict_put:nne {l_pdffile/Filespec}{F} { \l__pdffile_tmpa_str }
          \__pdffile_filename_convert_to_print:nN  { #2 } \l__pdffile_tmpa_str
          \pdfdict_put:nne {l_pdffile/Filespec}{UF}{ \l__pdffile_tmpa_str }
          \pdf_object_write:nne { #1 } { dict }
            {
              \pdfdict_use:n { l_pdffile/Filespec}
              \tl_if_empty:nF { #3 }
                {
                  /EF <</F~#3 /UF~#3>>
                }
            }
        \group_end:
      }
  }

\cs_new_protected:Npn \__pdffile_filespec_write:nnN #1 #2 #3
  {
    \tl_if_blank:nTF { #1 }
      {
        \msg_error:nn {pdffile}{target-name-missing}
      }
      {
        \group_begin:
          \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffile_tmpa_str
          \pdfdict_put:nne {l_pdffile/Filespec}{F} { \l__pdffile_tmpa_str }
          \__pdffile_filename_convert_to_print:nN  { #1 } \l__pdffile_tmpa_str
          \pdfdict_put:nne {l_pdffile/Filespec}{UF}{ \l__pdffile_tmpa_str }
          \pdf_object_unnamed_write:ne {dict}
            {
              \pdfdict_use:n { l_pdffile/Filespec}
              \tl_if_empty:nF { #2 }
                {
                  /EF <</F~#2 /UF~#2>>
                }
            }
        \tl_gset:Ne\g__pdffile_tmpa_tl{\pdf_object_ref_last:}
        \group_end:
        \tl_set_eq:NN#3\g__pdffile_tmpa_tl
      }
  }

\cs_set_eq:NN \pdffile_filespec:nnn \__pdffile_filespec_write:nnn
\cs_generate_variant:Nn \pdffile_filespec:nnn {nne,nnx}
\cs_new_protected:Npn \pdffile_embed_file:nnn #1 #2 #3
  { %               if #1 empty => only filespec
    %               if #2 empty => = #1
    \pdf_object_if_exist:nTF { #3 }
      {
        \msg_error:nnn { pdffile }{ object-exists } { #3 }
      }
      {
        \tl_if_blank:nTF { #1 }
          {
            \tl_set:Nn \l__pdffile_embed_ref_tl {}
          }
          {
            \file_get_full_name:nNTF {#1} \l_pdffile_source_name_str
              {
                \__pdffile_mimetype_set:VN
                  \l_pdffile_source_name_str
                  \l__pdffile_automimetype_tl
                \__pdffile_fstream_write:VN
                  \l_pdffile_source_name_str
                  \l__pdffile_automimetype_tl
                \tl_set:Ne \l__pdffile_embed_ref_tl { \pdf_object_ref_last: }
              }
              {
                \msg_error:nnn { pdffile }{ file-not-found }{ #1 }
              }

           }
        \prop_gput:Nne
           \g_pdffile_embed_prop
           { #3 }
           {
             { \tl_if_blank:nTF { #1 } {filespec}{file} }
             {\l_pdffile_source_name_str}
             {
               \tl_if_blank:nTF { #2 }
                 { \l_pdffile_source_name_str }
                 { \tl_to_str:n{#2}}
             }
           }
        \tl_if_blank:nTF { #2 }
          {
            \pdf_object_new:n   { #3 }
            \exp_args:Nnne
              \__pdffile_filespec_write:nnn
                %#1 dict, #2 target file name, #3 object ref
                { #3 }
                { #1 }
                {\l__pdffile_embed_ref_tl}
          }
          {
            \pdf_object_new:n   { #3 }
            \exp_args:Nnne
              \__pdffile_filespec_write:nnn
                %#1 dict, #2 target file name, #3 object ref
                { #3 }
                { #2 }
                {\l__pdffile_embed_ref_tl}
          }
      }
  }

\cs_new_protected:Npn \pdffile_embed_stream:nnn #1 #2 #3
  {
    %               if #2 empty => error
    \pdf_object_if_exist:nTF { #3 }
      {
         \msg_error:nnn { pdffile }{ object-exists } { #3 }
      }
      {
         \prop_gput:Nne
            \g_pdffile_embed_prop
            { #3 }
            {{stream}{}{\tl_if_blank:nTF {#2}{stream.txt}{\exp_not:n{#2}}}}
         \tl_if_blank:nTF {#2}
          { \__pdffile_mimetype_set:nN {stream.txt}\l__pdffile_automimetype_tl}
          { \__pdffile_mimetype_set:nN { #2 } \l__pdffile_automimetype_tl }
         \__pdffile_stream_write:nN
           { #1 }
           \l__pdffile_automimetype_tl
         \tl_set:Ne \l__pdffile_embed_ref_tl { \pdf_object_ref_last: }
         \pdf_object_new:n   { #3 }
         \exp_args:Nnee
           \__pdffile_filespec_write:nnn
             %#1 dict, #2 target file name, #3 object ref
             { #3 }
             { \tl_if_blank:nTF {#2}{stream.txt}{\exp_not:n{#2}} }
             {\l__pdffile_embed_ref_tl}
     }
  }

\cs_new_protected:Npn \pdffile_embed_stream:nnN #1 #2 #3
  {
     \tl_if_blank:nTF {#2}
      { \__pdffile_mimetype_set:nN {stream.txt}\l__pdffile_automimetype_tl}
      { \__pdffile_mimetype_set:nN { #2 } \l__pdffile_automimetype_tl }
     \__pdffile_stream_write:nN
       { #1 }
       \l__pdffile_automimetype_tl
     \tl_set:Ne \l__pdffile_embed_ref_tl { \pdf_object_ref_last: }
     \exp_args:Nee
       \__pdffile_filespec_write:nnN
         %#1 target file name, #2 object ref of stream, #3 object ref of filespec
         { \tl_if_blank:nTF {#2}{stream.txt}{\exp_not:n{#2}} }
         {\l__pdffile_embed_ref_tl}
         #3
     \prop_gput:Nee
        \g_pdffile_embed_prop
        { #3 }
        {{stream}{}{\tl_if_blank:nTF {#2}{stream.txt}{\exp_not:n{#2}}}}
  }

%% 
%%
%% End of file `pdfmanagement-testphase.ltx'.
